Scope issue? please help cannot figure out

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

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]
        };
    };
}