# Can'#t access children

**URL:** <https://forum.kirupa.com/t/can-t-access-children/304084>\
**Category:** Uncategorized\
**Created:** [February 1, 2010, 2:48pm UTC](https://forum.kirupa.com/t/can-t-access-children/304084 "2010-02-01T14:48:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxelcat](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/maxelcat/32/2854_2.png) [@maxelcat](https://forum.kirupa.com/u/maxelcat)\
**Post date:** [February 1, 2010, 2:48pm UTC](https://forum.kirupa.com/t/can-t-access-children/304084/1 "2010-02-01T14:48:05Z")

</div>

I have a simple class to create some buttons:

```auto
package {
 import flash.display.*;
 import flash.events.*;
 
 public class ControlButton extends Sprite {
 
:  
public var _gryBtn:GreyButton = new GreyButton();
      
public function createButton(what:String, iIndex:Number, m:Number):void {
// add name - its the url of the iamge without the swf eg introduction, 1999, mar2001
_gryBtn.name=ref;

```

in my main file I have a function that creates the buttons:

```auto

var gryBtn:ControlButton = new ControlButton();
gryBtn.addEventListener(MouseEvent.CLICK, sceneBtnClicked);

```

WHen I press the button I can get the name out easily by going

```auto

function sceneBtnClicked(e:Event):void{
  trace( e.target.ref)
}

```

all works fine  
Later on the code I want to loop through all these buttons but I can’t seem to get name to work

```auto

for (j:Number:0; j<this.container.numChildren, j++){
trace (this.container.getChildAt(j).ref);
}

```

brings up “access of possibly undefined property”  
I do have other mcs etc within that container which don’t have a ref  
but also trace (this.container.getChildAt(5).ref) doesn’t work and I know number 5 is one of the ones that does have a ref  
How do I use the ref to target the buttons  
thanks  
E
