Hi,
I've run into weird issue.I've a main game class which extends UIComponent and basecly glue all game logic together - main loop.Then I've app main.mxml file which initialize main game class,keep care of game screen state(main menu,game,game over,etc..) and add some ui control - flex is great for that.Nonetheless problem arrive when I'm trying listen on custom event in Main.mxml which is dispatched in Game class.
**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
<fx:Script>
<![CDATA[
protected function game_gameOverHandler(event:GameStateEvent):void
{
//This event never got dispatched
}
]]>
</fx:Script>
<game:Game id="game" includeIn="GameState" gameOver="game_gameOverHandler(event)"/>
I'm really stack in this - things seems simple but for reasons I unknown nothing seems to work.I tried capturing,bubbling event - nothing, event never got dispatched in Main.mxml.