In a nutshell, I’ve got many (hundreds of) different movieclips on stage that I have just generated using duplicateMovieClip. (this works fine.)
After generating each of the movie clips, I next need to replace them all individually with one of a handful of existing movieclips in the library.
The ‘targets’ (the placeholder MC’s I am trying to attachMovie onto) all exist within a parent MC. i.e.
_root.parent_mc
_root.parent_mc.duplicated_mc_1
_root.parent_mc.duplicated_mc_2
_root.parent_mc.duplicated_mc_3
_root.parent_mc.duplicated_mc_4
_root.parent_mc.duplicated_mc_5
etc… etc…
There’s a LOT of these duplicated MC’s, so I’m trying to use attachMovie within a loop to do the changing.
If I hard code the target into the script things work just fine. For example, this works as expected…
_root.parent_mc.duplicated_mc_1.attachMovie("symbol1", x, 0);
…where symbol1 is an MC in the library with the appropriate linkage/exported to first frame stuff for the actionscript.
However, I can’t seem to make things work using a variable in the same string.
In my loop I have created a variable to hold the identifier for the MC to be replaced. Something like:
for (i=1;i<100;i++){
var y:String = "duplicated_mc_" + i;
// Outputs duplicated_mc_1, duplicated_mc_2, etc. etc. up to 99.
}
Now I need to address the target MC using that y in a loop, like:
_root.parent_mc.y.attachMovie("symbol1", x, 0);
That doesn’t seem to work however, nor do various other things I’ve tried like
_root.parent_mc.this[y].attachMovie("symbol1", x, 0);
_root.parent_mc.[y].attachMovie("symbol1", x, 0);
etc… etc…
Tracing y in the same place gives me the same string as the hard coded value, so
I’m assuming I’m getting the syntax wrong, but all the info I can find seems to focus on putting dynamic variables within the brackets - which isn’t what I’m having trouble with (those I can seemingly substitute ok.)
Sorry if this is more obvious that I imagine, any advice much appreciated!