2011-06-03 60 views
-2

如何將一個CustomEvent作爲參數傳遞給一個類並稍後調度它?我想達到什麼樣的下面是一個例子 - 非工作如何傳遞一個CustomEvent作爲參數併發送它?

var container:Container = new Container(array, new ViewEvent(ViewEvent.PHOTO_SELECTED)); 
addChild(container); 

,並在容器:

public class Container extends Sprite 

public function Container(array:Array, e:ViewEvent):void 
{ 
    _objectsArray = array; 
    _event = e; 
    addEventListener(Event.ADDED_TO_STAGE, init); 
} 

private function selected():void 
{ 
    dispatchEvent(new ViewEvent(_event, true, false, _selectedID)); 
} 

所以當selected()被稱爲視圖事件是傳入構造函數被解僱。

+0

能否請你澄清?你問如何實現一些東西,但發佈代碼.........實現什麼? – 2011-06-03 11:35:00

+0

對不起,希望現在更清楚 – davivid 2011-06-03 11:42:18

+0

這似乎是部分代碼。你可以發佈調用selected()函數的代碼,還是有一個? – 2011-06-03 11:46:23

回答

0

剛剛意識到它不是Event我需要傳遞,而是字符串值。

var container:Container = new Container(array, ViewEvent.PHOTO_SELECTED); 

-

public function Container(array:Array, e:String):void 
{ 
_objectsArray = array; 
_event = e; 
addEventListener(Event.ADDED_TO_STAGE, init); 
} 

private function selected():void 
{ 
dispatchEvent(new ViewEvent(_event, true, false, _selectedID)); 
}