我不是代碼天才,而是行動腳本的粉絲。 你能幫我:AS3將變量參數傳遞給一個通用的函數Menu/SubItems
我有一個函數,取決於所選對象,將調用事件監聽器到一組已經在舞臺上的「子項目」(我想重用這個子項目與改變參數點擊,而不是創建幾個實例和幾個代碼)。
所以對於每個選定的「案例」我要diferent變量傳遞給那些「分項目」,像這樣:
function fooMenu(event:MouseEvent):void {
switch (event.currentTarget.name)
{
case "btUa1" :
trace(event.currentTarget.name);
// a bunch of code goes here
//(just cleaned to easy the view)
/*
HELP HERE <--
here is a way to pass the variables to those subitems
*/
break;
}
}
function fooSub(event:MouseEvent):void
{
trace(event.target.data);
trace(event.currentTarget.name);
// HELP PLEASE <-> How can I access the variables that I need here ?
}
btUa1.addEventListener(MouseEvent.CLICK, fooMenu);
btUa2.addEventListener(MouseEvent.CLICK, fooMenu);
btTextos.addEventListener(MouseEvent.CLICK, fooSub);
btLegislacao.addEventListener(MouseEvent.CLICK, fooSub);
任何幫助我嗎? 非常感謝。 :)
謝謝! 這裏清除我需要的東西: 在我的階段我有6個項目 - 對象和3個子項目 - 對象 當點擊項目(fooMenu)我重新排列這3個子項目,並需要給這3個新的點擊事件參數點擊時他們可以調用新的剪輯)。 我想你的解釋,但並沒有得到它的權利......在這裏: 'code' 功能fooSub(事件:的MouseEvent,BLA:字符串):無效 { \t跟蹤(event.currentTarget.name +」 - 「+ BLA); // bla將是一個剪輯名稱。 } in fooMenu case: 'code'btTextos.addEventListener(MouseEvent.CLICK,fooSub(「jocasta」)); – John 2012-07-30 17:48:12
whish我可以投票了(呵呵太新手了) – John 2012-07-30 17:58:56
通知編輯答案;)希望它有幫助。如果你想在你的問題下面添加一些信息到你的問題使用評論,或者編輯它。 – mswiszcz 2012-07-30 18:18:23