# AS2 Adding multiple movieclips within a for loop

**URL:** <https://forum.kirupa.com/t/as2-adding-multiple-movieclips-within-a-for-loop/327530>\
**Category:** flash\
**Created:** [March 7, 2012, 3:58pm UTC](https://forum.kirupa.com/t/as2-adding-multiple-movieclips-within-a-for-loop/327530 "2012-03-07T15:58:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![BadBoyMcCoy](https://avatars.discourse-cdn.com/v4/letter/b/bbe5ce/32.png) [@BadBoyMcCoy](https://forum.kirupa.com/u/BadBoyMcCoy)\
**Post date:** [March 7, 2012, 3:58pm UTC](https://forum.kirupa.com/t/as2-adding-multiple-movieclips-within-a-for-loop/327530/1 "2012-03-07T15:58:46Z")

</div>

Hi,

I’m sure this has been asked before but couldn’t find anything to my specific problem.

Basically I have 5 movieclips I want positioned around the stage. So I figure the best way to this is with a for loop. However the way I’ve coded it doesn’t appear to add new movieclips and seems to just move the first movieclip 5 times and it always ends up with an x of 169. Here’s my code:

```auto
for (i=0; i<5; i++){
            
    var barName:MovieClip = 
    _root.game.attachMovie("butSquare","r1wBar"+i,_root.getNextHighestDepth());

    barName._width = 22;
    barName._height = 344;
    barName._y = -170;
            
    if(i == 0) {
        barName._x = -168;
    }
    else if(i == 1) {
        barName._x = -105;
    }
    else if(i == 2) {
        barName._x = -11;
    }
    else if(i == 3) {
        barName._x = 79;
    }
    else if(i == 4) {
        barName._x = 169;
    }
}

```

Is it something to do with the way I’m referencing the movieclip?

Any help would be greatly appreciated.

McCoy
