hi,
at the moment i have a list of commands :
_level1.gotoandstop(1);
_level2.gotoandstop(1);
_level3.gotoandstop(1);
_level4.gotoandstop(1);
and so on for a few more…
which returns all my animations to their first frame, which contains a stop();, so i can then trigger them at the desired time.
But whilst this works, i was sure there was a more elegant way of doing this with something like
for (var loop = 0; loop <13; loop++) {
_level[loop]gotoandstop(1);
}
which doesn’t seem to work, anyone got any ideas?
close
this["_level"+loop].gotoandstop(1);
the brackets work with a string that make up an entire scope using object[“object”] no one object can be made out of part of an object and part of [] - either outside or inside for one. So the outside object here is the this and we are using that to reference the _level# object which is global for any scope - _level1 anywhere is _level1, same for in this. so then this["_level"+loop] will reference _level0, _level1, … _level12. if you want it to start at 1, set var loop = 1 instead of 0. using < goes upto but doesnt include the number specified (13) so consider that, depedning on what your range is.
Thanks for both showing me how to do it, and explaining how it works.
One day I’m going to be good enough to answer some of the questions on here instead of just asking them.