Re: [問題] 關於AS3.0 偵聽事件的函數參數第2問
t1_btn.addEventListener(MouseEvent.CLICK, getSetup);
t2_btn.addEventListener(MouseEvent.CLICK, getSetup);
function getSetup(event:MouseEvent):void
{
switch(event.currentTarget as SimpleButton)
{
case t1_btn:
set.text=String(35);
break;
case t2_btn:
set.text=String(70);
break;
}
}
上一篇的版眾大已經回答的差不多了~用event判斷
※ 引述《godsing (執著是苦)》之銘言:
: 雖然之前問過了,不過還是弄不出來,沒碰上實際例子,也不知道要怎麼繼續問
: 小弟太資潛了....
: 這次是實際碰上的問題,其實是把之前的AS2.0作品要改成3.0所碰上的問題
: t1_btn.addEventListener(MouseEvent.CLICK, getSetup1);
: t2_btn.addEventListener(MouseEvent.CLICK, getSetup2);
: function getSetup1(event:MouseEvent):void {
: set.text=String(35);
: }
: function getSetup2(event:MouseEvent):void {
: set.text=String(70);
: }
: 實際按鈕有很多,這裡取2個
: 請問我有什麼辦法可以把它簡化成
: t1_btn.addEventListener(MouseEvent.CLICK, getSetup);
: t2_btn.addEventListener(MouseEvent.CLICK, getSetup);
: 呼叫同一個getSetup,但是set.text的值依按鈕的不同而改變
: 當然寫很多function是可以解決,但是這樣就不用學了 = =
: 感謝指點!!
--
Dragon in Underware 3UB
Trample.
Any man creature become 0/1 weeky chiken.
If a woman deal damage to Dragon in Underware, Dragon in Underware become 0/1 weaky chiken.
If Dragon in Underware deal damage, put many 1/1 red Ooze token into play
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.138.32.78
※ 編輯: sledogerunir 來自: 140.138.32.78 (03/09 16:15)
推
03/09 16:56, , 1F
03/09 16:56, 1F
→
03/09 21:59, , 2F
03/09 21:59, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 3 篇):