假設您正在使用PopUpManager將打開您的自定義TitleWindow中,PopUpManager將應分派自定義事件與球員價值的數量,這將打開TitleWindow中可以偵聽該事件的組件。無需編寫正式的測試,代碼是這樣的:
// In The component that creates the TitleWindow:
var newTitleWindow : MyTitleWindow = new MyTitleWindow();
newTitleWindow.addEventListener('numberOfPlayersChanged', onNumberofPlayersChanged);
PopUpManager.addPopUp(newTitleWindow , this);
您的自定義事件類:
package events
{
import flash.events.Event;
public class MyEvent extends Event
{
public var numberOfPlayers:int;
public function MyEvent (type:String, bubbles:Boolean=false, cancelable:Boolean=false)
{
super(type, bubbles, cancelable);
}
}
}
在標題窗口,調度該事件:
var newEvent : MyEvent = new MyEvent('numberOfPlayersChanged')
newEvent.numberOfPlayers = // whatever procedure you use to get the number of players
dispatchEvent(newEvent);
再回到模板它創建標題窗口:
protected function onNumberofPlayersChanged(event:MyEvent):void{
trace(event.numberOfPlayers);
// do something else with number of players
}
關於主應用程序,顯示層次結構中的TitleWindow在哪裏?你用PopUpManager打開titleWindow嗎?或者以其他方式? – JeffryHouser
我能夠使它與事件:)感謝flextras和是的,我打開它使用popupmanager – Alon