# Sprite.addChild Problem please help

**URL:** https://forum.kirupa.com/t/sprite-addchild-problem-please-help/258359
**Category:** flash
**Created:** [April 23, 2008, 12:05pm UTC](https://forum.kirupa.com/t/sprite-addchild-problem-please-help/258359 "2008-04-23T12:05:34Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![adnan794](https://avatars.discourse-cdn.com/v4/letter/a/8edcca/32.png) [@adnan794](https://forum.kirupa.com/u/adnan794)
#### Post date: [April 23, 2008, 12:05pm UTC](https://forum.kirupa.com/t/sprite-addchild-problem-please-help/258359/1 "2008-04-23T12:05:34Z")

</div>

Hi all.

I am generating dynamic menus from an xml file. When I create movie clip buttons inside a for loop I am adding these to a sprite so that I can add child to the stage and chage its position. when I come out of this loop the sprite.numChildren is coming out to be 0 where as inside the loop if I trace it its comes out fine here is the code.

var sprite:Sprite = new Sprite();  
sprite.x = 50;  
sprite.y = 50

// generating movieclip menus  
for ( var i:int = 0; i \< array.lenght;i++){

var menu:MenuClassMoiveClip = new MenuClassMovieClip();

menu.x = menu.width\*i;  
sprite.addChild(menu);  
trace(sprite.numChildren); // gives 1,2,3 and so on depending on array lenght

}//

for (var j:int= 0; j \< sprite.numChildren ; j++){

trace(sprite.numChildren); // nothing is traced even it does not enter into the for loop because sprite.numChildren is 0  
}

Any help will be really appreciated

Thanks a bunch
