# New to AS3, remember lastBtn?

**URL:** https://forum.kirupa.com/t/new-to-as3-remember-lastbtn/246479
**Category:** Uncategorized
**Created:** [December 11, 2007, 3:33pm UTC](https://forum.kirupa.com/t/new-to-as3-remember-lastbtn/246479 "2007-12-11T15:33:43Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jamiller](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jamiller/32/3433_2.png) [@jamiller](https://forum.kirupa.com/u/jamiller)
#### Post date: [December 11, 2007, 3:33pm UTC](https://forum.kirupa.com/t/new-to-as3-remember-lastbtn/246479/1 "2007-12-11T15:33:43Z")

</div>

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:

```auto

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].@title;
        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:

```auto

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
