Groups | Blog | Home
all groups > flash actionscript > may 2004 >

flash actionscript : how to get instance names dynamically?


aznan8
5/6/2004 8:25:15 PM
Hi!
I have a whole lot of movieclips instanced MC1, MC2, MC3... I want to turn off
the visibility for all of these, but since there are so many of them I want to
use a for loop to do it. I have tried to use this code:

for(i = 0; i < 10; i++) {
["MC"+i]._visible = false;
}

but it didn't work. I have also tried to use a textfield to read from, like
this:

for(i = 0; i < 10; i++) {
tempText = "MC"+i;
tempText.text._visible = false;
}

of course, that didn't work either.
Does anyone here posses the knowledge of how it's done?
Does that anyone feel like sharing their insights with their fellow flashers?
Thanks in advance!
CesareRocchi
5/6/2004 8:44:27 PM
This should work

for(i = 0; i < 10; i++) {
tempText = eval("MC"+i);
tempText.text._visible = false;
}

Someoneelse would like the 'this[...]' notation ...
I prefer eval

HTH,

mandingo
5/7/2004 12:07:57 AM
Hi,

for(things in this){
if(typeof(this[things]) == "movieclip"){
this[things]._visible = false;
}
}

that will check all movieClips and make them invisible...

hope that helps
AddThis Social Bookmark Button