Passing var to movie control command?

Hi,

I have question that I believe should be simple. Here it is;

instead of writing for example;

test.gotoAndPlay(2);

I wrote this but does not seem to work;

x = “test”;
x.gotoAndPlay(2);

Is there a format that I should use to get this to work? Thanks.

try this…
dont know if it’ll work but what the hey…


x = eval("_root.test");
x.gotoandPlay(2);

i know this works when doing dynamic stuff:


for(i=0;i<5;i++){
_root["movieclip" + i].play();

}

hmm =)

works!! thx… what does eval do anyways?

eval( ) works when you want to evaluate something as litteral… such as a variable name etc…

since you were doing
x = “test”; it was assigning it as a string.

if you do the eval(“test”) it goes, ok, this must be a variable name or an object or something other than a string =)

its intended for dyanamic thigns , its most handy =)

the eval way is deprecated in MX, so you might just wanna stick with the 2nd method :):

x = "test"
_root[x].gotoAndPlay(2);

or do what ahmed said… =)

even though eval() is still king in other languages… =)

nice! thanks for the help Raydred and ahmed :slight_smile: