# Scope issue? please help cannot figure out

**URL:** <https://forum.kirupa.com/t/scope-issue-please-help-cannot-figure-out/234910>\
**Category:** Uncategorized\
**Created:** [August 7, 2007, 4:51am UTC](https://forum.kirupa.com/t/scope-issue-please-help-cannot-figure-out/234910 "2007-08-07T04:51:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mfey](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mfey/32/3661_2.png) [@mfey](https://forum.kirupa.com/u/mfey)\
**Post date:** [August 7, 2007, 4:51am UTC](https://forum.kirupa.com/t/scope-issue-please-help-cannot-figure-out/234910/1 "2007-08-07T04:51:00Z")

</div>

I have created three buttons that I want to load pictures when clicked. I can’t seem to get the value of each button when it was created in the array. The way I have tried works for me in AS2 but the buttons return undefined in the following AS3 code. I have been trying to figure this out for a week now, any help is much appreciated

```auto
var butArray:Array = new Array();
function createThumbs(){
    var myXML:XML=new XML(xmlLoader.data);
    for (var z:int = 0; z<(myXML.image.length()); z++){
        var but:square = new square();
        addChild(but);
        but.name = "button" + z;
        butArray[z] = this.getChildByName("button" + z);
        butArray[z].x = z*300 + ((stage.stageWidth/myXML.image.length()) - z);
        butArray[z].y = 500;
        butArray[z].buttonMode = true;
        butArray[z].addEventListener(MouseEvent.CLICK, loadThumb);
        var thumbs = butArray[z];
        thumbs.num = z;
        [COLOR=Red]function loadThumb(myEvent:Event):void{
            trace(this.num);[/COLOR]
        };
    };
}

```
