Levels as arrays

Hi!

Im trying to make a button that makes all existing levels go to frame 2.

The exhausting way would be something like this:

on (press) {
_level1.gotoAndStop(2);
_level2.gotoAndStop(2);
…etc, etc…
}

Well, I have a lot of levels, so I figured I would use a for-loop to do this. However, I dont know how to index the number in the _leveli variable (i being the index-number). I tried something like this, but doesnt work:

on (press) {
for(i=1; i < 20; i++)
{
tempLevel = _level + i;
tempLevel.gotoAndStop(2);
}
}

…and…

on (press) {
for(i=1; i < 20; i++)
{
tempLevel = “_level” + i;
tempLevel.gotoAndStop(2);
}
}

…and…


on (press) {
for(i=1; i < 20; i++)
{
_level + i.gotoAndStop(2);
}
}

Does anyone have a good solution to this?

Thanks

use eval("_level"+i)

this will convert the string “_level”+i to the actual reference of the level.

Thanks, that worked great :smiley: