Re: [問題] 關於AS3.0 偵聽事件的函數參數第2問

看板Flash作者 (隱密忍者農丸)時間14年前 (2010/03/09 16:07), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串2/3 (看更多)
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
GOOD^^
03/09 16:56, 1F

03/09 21:59, , 2F
酷耶! 感謝!!
03/09 21:59, 2F
文章代碼(AID): #1BbW6yn7 (Flash)
文章代碼(AID): #1BbW6yn7 (Flash)