New to AS3, remember lastBtn?

I’m new to AS3 and I need to know how to remember the last button that was clicked. I am currently attaching an mc to the stage from the library x:Number of times depending on how many nodes I have in my xml. I then set the name of the buttons: setBtn.name = “setBtn”+j; which works great.

Here is my AS3 code:


var totalBtns:int;
var btnName:Array = [];
var lastBtn = "setBtn0"; //trying to set the first lastBtn - doesn't work...

function loadXML(e:Event):void {
    var xml:XML = new XML(loader.data);
    totalBtns = xml.item.length();
    for(var j=0; j<totalBtns; j++) {
        btnName[j] = xml.item[j][email protected];
        var setBtn:SetBtn = new SetBtn();        
        addChild(setBtn);
        setBtn.x = 644;
        setBtn.y = 81+setBtn.height*j;
        setBtn.setBtnText.setText.text = btnName[j];
        setBtn.name = "setBtn"+j;        
        Xbtn.basic(setBtn);   //custom btn class to mimic AS2 button code    
        var sbtn = getChildByName("setBtn"+j);        
        sbtn.useHandCursor = true; //this doesn't work either. weird...        
        sbtn.xRollOver = function() {
            if(this.currentFrame != 7) { // detects if the sbtn is on the "hitstate"
                this.gotoAndPlay("over");
            }
        }
        sbtn.xRollOut = function() {
            if(this.currentFrame != 7) {
                this.gotoAndStop(1);
            }
        }
        sbtn.xRelease = function() {
            parent.getChildByName(lastBtn);
            lastBtn.gotoAndStop(1); // doesn't work...
            this.gotoAndStop(7);
            lastBtn = this.name;
        }
    }
}

I pretty sure it’s something simple. The new ways of dealing with variables is messing me up.

My AS2 code (that works…) looks like so:


btn.onRelease = function() {
     lastBtn.gotoAndStop(1);
     this.gotoAndStop(7);
     lastBtn = this;
}

Please help! I’ve tried everything and I can’t get anything to work…

Thanks!

Jeff