我用flash做了三个按钮,鼠标点击它们分别执行不同事件,在as代码里面怎样判断?比如if(点击的是A按钮){
展开全部
a.addEventListener(MouseEvent.CLICK, doSomething);
b.addEventListener(MouseEvent.CLICK, doSomething);
c.addEventListener(MouseEvent.CLICK, doSomething);
function doSomething(evt:MouseEvent):void{
if (evt.currentTarget.name == "a"){
trace("click button a");
}else if(evt.currentTarget.name == "b"){
trace("click button b");
}else{
trace("click button c");
}
}
选择分支多的话,建议使用switch
b.addEventListener(MouseEvent.CLICK, doSomething);
c.addEventListener(MouseEvent.CLICK, doSomething);
function doSomething(evt:MouseEvent):void{
if (evt.currentTarget.name == "a"){
trace("click button a");
}else if(evt.currentTarget.name == "b"){
trace("click button b");
}else{
trace("click button c");
}
}
选择分支多的话,建议使用switch
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询