# addChild in while loop

**URL:** <https://forum.kirupa.com/t/addchild-in-while-loop/278271>\
**Category:** flash\
**Created:** [December 25, 2008, 9:06am UTC](https://forum.kirupa.com/t/addchild-in-while-loop/278271 "2008-12-25T09:06:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ThaJock](https://avatars.discourse-cdn.com/v4/letter/t/9de0a6/32.png) [@ThaJock](https://forum.kirupa.com/u/ThaJock)\
**Post date:** [December 25, 2008, 9:06am UTC](https://forum.kirupa.com/t/addchild-in-while-loop/278271/1 "2008-12-25T09:06:15Z")

</div>

I’m trying to import a class that adds an instance of a a MovieClip multiple times, one below the other. I have used this type of loop before and it has worked fine. However, when I use it in an external class it seems to only disply the child added on last iteration.

Here is the code for the external class:

package classes {  
import flash.display.\*;

```
public class TheBox extends MovieClip{
    var the_Box:MovieClip = new theBox();
    
    public function TheBox () {
        var a:int = 0
        while ( a &lt; 3 ) {
            the_Box.y = a * the_Box.height;
            addChild(the_Box);
            a++;
        }            
    }
}

```

}

Here’s the code for the flash poject:

import classes.TheBox;  
var myBox:TheBox = new TheBox();  
addChild(myBox);

Can anyone tell me why it only shows the child added on the last iteration of the loop?
