# Problem with addChild()

**URL:** <https://forum.kirupa.com/t/problem-with-addchild/266637>\
**Category:** flash\
**Created:** [July 22, 2008, 10:21pm UTC](https://forum.kirupa.com/t/problem-with-addchild/266637 "2008-07-22T22:21:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![magnusvs](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@magnusvs](https://forum.kirupa.com/u/magnusvs)\
**Post date:** [July 22, 2008, 10:21pm UTC](https://forum.kirupa.com/t/problem-with-addchild/266637/1 "2008-07-22T22:21:53Z")

</div>

Hi! I am trying to create a menu dynamically by using adding instances of a movie clip (a button) to the stage.

1. First I create a movieclip named mcMainButtons.
2. Then I have a loop that create instances of the buttons which are added to the mcMainButtons with the addChild function.
3. At last I add the mcMainButtons to the stage with addChild.

My problem arises when I try to access the buttons. I have named them “btnHome”, “btnGallery” etc. (I have traced their names to see that this is correct), but when I try to access them, e.g. by writing trace(mcMainButtons.btnHome.x), I get an error telling me that “TypeError: Error #1010: A term is undefined and has no properties.”

If anybody could help me solve my problem, I would be really thankful:)

(here is the relevant code, just in case (colButtons\_main is just an array with the button names))

> 

function SetMainButtons() {  
var i:int;  
var strBtnName:String  
mcMainButtons=new MovieClip;  
mcMainButtons.name=“mcMainButtons”;

for (i=0; i\<=colButtons\_main.length-1; i++) {

var btnMainButton:mcTop\_btn=new mcTop\_btn;  
btnMainButton.name=“btn”+colButtons\_main\*;  
btnMainButton.txtName.text=colButtons\_main\*;  
mcMainButtons.addChild(btnMainButton);  
btnMainButton.x= //formula (irrelevant)  
btnMainButton.y= 20

}  
mcTop.addChild(mcMainButtons);  
mcMainButtons.x=0  
mcMainButtons.y=0  
trace(mcMainButtons.btnHome.x)  
}
