flash as3.0多個按鈕語法

2014-06-22 2:17 am
我的動畫裡有7個按鈕,而在影格中寫好語法後,測試結果是1021:函數定義重複
請問哪裡有問題嗎

附上我寫的語法
a1.a2.a3.a4.a5.a6.s1是按鈕實體名稱

stop();
a1.addEventListener(MouseEvent.CLICK,myClick);
function myClick(e:MouseEvent):void {
gotoAndPlay(1,"a1");
}
a2.addEventListener(MouseEvent.CLICK,myClick);
function myClick(e:MouseEvent):void {
gotoAndPlay(1,"a2");
}
a3.addEventListener(MouseEvent.CLICK,myClick);
function myClick(e:MouseEvent):void {
gotoAndPlay(1,"a3");
}
a4.addEventListener(MouseEvent.CLICK,myClick);
function myClick(e:MouseEvent):void {
gotoAndPlay(1,"a4");
}
a5.addEventListener(MouseEvent.CLICK,myClick);
function myClick(e:MouseEvent):void {
gotoAndPlay(1,"a5");
}
a6.addEventListener(MouseEvent.CLICK,myClick);
function myClick(e:MouseEvent):void {
gotoAndPlay(1,"a6");
}
s1.addEventListener(MouseEvent.CLICK,myClick);
function myClick(e:MouseEvent):void {
gotoAndPlay(1,"s1");
}

回答 (2)

2014-06-22 7:32 pm
✔ 最佳答案
大大好,在相同 mc 內,不同 function 不可以有相同的名字,
所以改成下面寫法,應該就可以了

stop();
a1.addEventListener(MouseEvent.CLICK,myClick_a1);
function myClick_a1(e:MouseEvent):void {
gotoAndPlay(1,"a1");
}
a2.addEventListener(MouseEvent.CLICK,myClick_a2);
function myClick_a2(e:MouseEvent):void {
gotoAndPlay(1,"a2");
}
a3.addEventListener(MouseEvent.CLICK,myClick_a3);
function myClick_a3(e:MouseEvent):void {
gotoAndPlay(1,"a3");
}
a4.addEventListener(MouseEvent.CLICK,myClick_a4);
function myClick_a4(e:MouseEvent):void {
gotoAndPlay(1,"a4");
}
a5.addEventListener(MouseEvent.CLICK,myClick_a5);
function myClick_a5(e:MouseEvent):void {
gotoAndPlay(1,"a5");
}
a6.addEventListener(MouseEvent.CLICK,myClick_a6);
function myClick_a6(e:MouseEvent):void {
gotoAndPlay(1,"a6");
}
s1.addEventListener(MouseEvent.CLICK,myClick_s1);
function myClick_s1(e:MouseEvent):void {
gotoAndPlay(1,"s1");
}
2014-06-22 2:11 pm
同一層裡的函式名稱不能重複


收錄日期: 2021-05-01 19:11:11
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20140621000010KK07836

檢視 Wayback Machine 備份