views:

68

answers:

1

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.

A: 

Problem is solved.Actually I little bit lied about when dispatchEvent because for test purpose I dispatchEvent append constructor initialize process.Ok, my bad I'm more experienced and comfortable with pure actionscript - but is it true that I can't listen on event in app Main.mxml from component while it constructor initialize process is done?Because after that everything works smoothly.

Rudis