How do I execute this string in flashMX2004?
June 16, 2004 3:36 AM   RSS feed for this thread Subscribe

How do I execute a string in flashMX2004?

say ive got the following code (simplified):
for(x=0;x<3 00;x++){br> "mc"+x+".gotoAndPlay(10)"; // this is the string i want to execute
}

eval() does not do the trick
google doesn't help now can ask.metafilter?

That bit of code came out strange. Here it is again for your viewing pleasure:

for(x=0;x<3 00;x++){mc+x+.gotoandplay(10);}br>
i of course want to execute the string mc+x+.gotoAndPlay(10)
posted by FidelDonson to computers & internet (4 comments total)
I swear i did not put that broken breaktab at the end of my line of sweet code.
posted by FidelDonson at 3:45 AM on June 16, 2004


I don't know ActionScript, but it's supposed to be a lot like Javascript. In Javascript, you can reference an object with a string through its parent using bracket notation. For example, if mcx is a global object, it can be called through the window object:

window["mc"+ x].gotoandplay(10)
posted by nikzhowz at 4:24 AM on June 16, 2004


nikzhowz is basically right, but in Flash you need to put the containing movieclip name before the ["mc"+x] bit. So if your mc0, mc1... mcx clips are on the root, you'd do this:

for ( x=0; x<300; x++ )
{
_root["mc"+x].gotoAndPlay ( 10 );
}

If they were in a movieclip called 'fideldonson':

for ( x=0; x<300; x++ )
{
fideldonson["mc"+x].gotoAndPlay ( 10 );
}

BTW, you're getting a "br>" because x<300 is starting a html tag. Using the HTML < instead fixes this.
posted by toby\flat2 at 5:00 AM on June 16, 2004


Thank you all - everything works now.
posted by FidelDonson at 5:03 AM on June 16, 2004


« Older So I was blessed this past wee...   |   MovieFilter? - When a film sho... Newer »
This thread is closed to new comments.


Related Questions
hello, world (of programming) August 17, 2008
I need skillz February 18, 2008
Where to begin with Ruby on Rails? December 29, 2007
I have some savings and would like to become a... May 20, 2007
What books should be on my "personal CS degree"... November 6, 2006