Actionscript, converting a variable in to a thingy

Soldato
Joined
25 Sep 2003
Posts
3,750
Location
Manchester
I've got a variable that is the name of a movieClip but if I try doing basically the following it doesn't work:


var myVar:String;

myVar= "myMovieClip";

myVar.alpha = .50;


This in my brain is saying, make the "myvar" variable have the value "myMovieClip" and then on the last line it's basically saying, myMovieClip.alpha = .50

So, is it because it's a String variable that's causing the issue or something else?

Cheers for helping me out in advance.
 
Last edited:
Haven't used flash in a while although the following should work.

this[myVar].alpha = .50;

or eval() although I think that is depreciated.
 
My guess:

You're interpreting it as myMovieClip.alpha, whereas it's actually aString.alpha (or, "myMovieClip".alpha); and i'm guessing that a string object doesn't contain that method.

Can you define the variable as a MovieClip? I don't know action script so i'm guessing.
 
Thanks for the replies. I tried defining it as a movie clip but that just brought up a different error. :(

I expect the whole way I'm trying to go about it is wrong really. I'll have to have a look and read up more and attempt it another way.
 
i suspect the quotes caused a type mismatch error when setting as a MovieClip.

in AS2.0
Code:
var myVar:MovieClip = myMovieClip;
myVar._alpha = 50;
 
Back
Top Bottom