# addChild in a for loop

**URL:** <https://forum.kirupa.com/t/addchild-in-a-for-loop/249471>\
**Category:** flash\
**Created:** [January 19, 2008, 1:40am UTC](https://forum.kirupa.com/t/addchild-in-a-for-loop/249471 "2008-01-19T01:40:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![icenine](https://avatars.discourse-cdn.com/v4/letter/i/46a35a/32.png) [@icenine](https://forum.kirupa.com/u/icenine)\
**Post date:** [January 19, 2008, 1:40am UTC](https://forum.kirupa.com/t/addchild-in-a-for-loop/249471/1 "2008-01-19T01:40:51Z")

</div>

I’m just not sure what I’m doing wrong with this…any and all help appreciated.

I’m trying to dynamically create a menu specified by the contents of a text file. If the text file has 3 pages listed, 3 buttons are pulled from the library with 3 links…

```auto

    function onDataLoad(evt:Event){
    
    //Load from text Document
    myCount.number = evt.target.data.TotalPageCount;
       
    //Set original y coordinate       
         var myYCoord:Number = 20; 
    //initiate for loop to populate all fields 
         for(var i=1; i <= myCount.number ;i++){ 
    // Create variable number of newButtons     
         this["newButton" + i +":theButton"] = new theButton();
    // Add text to dynamic text fields.
         this["Page"+i].text = evt.target.data["Page" + i];
    //use addChild to add var number of buttons (seems to be where the issue lies
         this.addChild(new this["newButton"+i]());
         
         
    //move Button down     
         this["newButton"+i].y = myYCoord ;
            myYCoord = myYCoord + 30;

         }

    }

```

Again, any and all help is appreciated.
