Harish Ambady
Harish Ambady

Reputation: 13171

target variable refernce name of a event listener

How to get the target variable refernce name of a event listener

   var key1:BtnKey=new BtnKey;
    var key2:BtnKey=new BtnKey;
    key1.addEventListener(MouseEvent.CLICK,function(e:MouseEvent):void{
                checkAnswer(e,qset)
            });
    key2.addEventListener(MouseEvent.CLICK,function(e:MouseEvent):void{
                checkAnswer(e,qset)
            });

function checkAnswer(e:MouseEvent,qset:Number):void{
//here I want the target variable reference ("key1" or "key2")  
    //e.target only gives the movieclip refernce like "[Object BtnKey]"
}

`

Upvotes: 0

Views: 388

Answers (1)

laurent
laurent

Reputation: 90863

Use e.currentTarget to get the button that was clicked on. If you need to find out whether you have key1 or key2, use a strict equality comparison:

if (e.currentTarget === key1) {
    // Do something
} else if (e.currentTarget === key2) {
    // Do something else
}

Upvotes: 1

Related Questions