0

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

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

`

4

1 回答 1

1

用于e.currentTarget获取被点击的按钮。如果您需要确定是否有key1or key2,请使用严格的相等比较:

if (e.currentTarget === key1) {
    // Do something
} else if (e.currentTarget === key2) {
    // Do something else
}
于 2012-07-31T07:19:05.317 回答