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”+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(;
    totalBtns = xml.item.length();
    for(var j=0; j<totalBtns; j++) {
        btnName[j] = xml.item[j][email protected];
        var setBtn:SetBtn = new SetBtn();        
        setBtn.x = 644;
        setBtn.y = 81+setBtn.height*j;
        setBtn.setBtnText.setText.text = btnName[j]; = "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"
        sbtn.xRollOut = function() {
            if(this.currentFrame != 7) {
        sbtn.xRelease = function() {
            lastBtn.gotoAndStop(1); // doesn't work...
            lastBtn =;

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 = this;

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