duplicateMovieClip Issues

Okay, so what I want is a set of 5 boxes.
I want these boxes arranged 2 per row, so there should be 3 rows in total with the last row only having 1 box in it.


  [  ]   [  ]
  [  ]   [  ]
  [  ]

Exactly like the above example.

Now I’m doing this by duplicating the 1 mc 5 times, here is my code:


onClipEvent(enterFrame) {
        var i = 1
        var ctr = 1
        
        while (i < 5) {
                
                if (ctr = 1) {
                        
                        mctemp = _root.picture1.duplicateMovieClip(i, i);
                        mctemp._x = 300;
                        i++;
                        ctr = 2;
                }
                else {
                        
                        mctemp = _root.picture1.duplicateMovieClip(i, i);
                        mctemp._x = 43;
                        mctemp._y = 100;
                        i++;
                        ctr = 1;
                        
                }
                
        }
        
}


And all I get is out put is the first row of boxes…

ie:


  [  ]  [  ]

and no more. Can anyone see the error in my code?

Thanks in advance guys,
RaraAvis

Here’s some working code, place it on the timeline in which your movieclip is in.


box._visible = 0;
spacing = {x:100, y:100};
for (i=1; i<=5; i++) {
	mc = box.duplicateMovieClip("box"+i, i);
	i%2 == 0 ? mc._x=box._x+spacing.x : mc._x=box._x;
	i<=2 ? mc._y=box._y : i>4 ? mc._y=box._y+(2*spacing.y) : mc._y=box._y+spacing.y;
}

Updated version, now totally dynamic: change the amount of boxes and watch :slight_smile:


box._visible = 0;
spacing = {x:100, y:100};
for (i=1; i<=3; i++) {
	mc = box.duplicateMovieClip("box"+i, i);
	i%2 == 0 ? mc._x=box._x+spacing.x : mc._x=box._x;
	i%2 == 0 ? mc._y=box._y+((i/2-1)*spacing.y) : mc._y=box._y+(((i-1)/2)*spacing.y);
}