0
我遇到了一個奇怪的問題。我是一個主要的遊戲類,它擴展了UIComponent並將所有遊戲邏輯basecly粘合在一起 - 主循環。然後,我已經創建了main.mxml文件,它初始化了主要的遊戲類,保持遊戲屏幕狀態(主菜單,遊戲,遊戲結束等等),並添加了一些ui控制 - flex很棒。但是當問題到達時我正在嘗試在Game類中調度的Main.mxml中監聽自定義事件。Flex 4 - 從UIComponent擴展自定義類中聽到Main.mxml中的事件問題
**GameStateEvent.as**
public class GameStateEvent extends Event
{
public static const GAME_OVER:String = "gameOver";
public static const NEW_LEVEL:String = "newLevel";
public function GameStateEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
{
super(type, bubbles, cancelable);
}
override public function clone():Event
{
return new GameStateEvent(type, bubbles, cancelable);
}
}
Game.as
[Event(name="gameOver", type="custom.events.GameStateEvent")]
public class Game extends UIComponent
private function checkforEndGame():void
{
if(_gameOver == true)
{
dispatchEvent(new GameStateEvent(GameStateEvent.GAME_OVER)); //true
}
}
Main.mxml
3210我真的堆在這 - 的東西,看起來簡單,但原因不明我什麼都不似乎work.I嘗試捕獲,冒泡事件 - 沒有,事件從未在Main.mxml中派發。
Everyhing看起來很適合我。從事件監聽器備份。你確定這個活動被解僱嗎? – JeffryHouser 2010-09-17 18:44:50
我與Flextras,這一切看起來不錯,假設dispatchEvent真的被checkForEndGame調用。唯一我能想到的是:GameStateEvent是否在你的custom.events包中? – 2010-09-17 19:16:26
是的,事件被觸發,因爲dispatchEvent返回true,如果我在Game.as中的addEventListener監聽器得到響應相同的事情,當我在Main.mxml中dispatchEvent,但由於未知原因,當我在Game.as中dispatchEvent並在Main.mxml監聽器中監聽從未被擊中。 – Rudis 2010-09-18 06:37:33