目标变量引用事件侦听器的名称

时间:2012-07-31 06:54:44

标签: actionscript-3 flash mouseevent flash-cs5

如何获取事件侦听器的目标变量引用名称

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

`

1 个答案:

答案 0 :(得分:1)

使用e.currentTarget获取点击的按钮。如果您需要了解自己是key1还是key2,请使用严格的相等比较:

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