View Full Version : Attaching movieclips using for loop

07-21-2009, 10:08 AM
I've been trying to use a for loop to attach a few movie clips to the stage in vain. I couldn't find any relevant examples in neither my flash manual nor the flash help nor the internet.

I have a few movie clips (let's say five) that I have created manually. I want to attach them to the stage using the for loop.

If I had to attach a single instance, I would do it as follows:

var pic1:MovieClip = new Pic1();
pic1.x = 10;
pic1.y = 15;

So, I thought that using a for loop would go as follows:

for (var i:Number = 1; i < 6; i++){
var ["pic"+i]:MovieClip = new ["Pic"+i]();
["pic" + i].x = 10;
["pic" + i].y = 15;
addChild["pic" + i];

I come from an AS2 background and this is what I could come up with whilst looking for solutions on the Web. The code doesn't work. Can anybody please tell me what I'm doing wrong and how should the code be amended?