I'm having a huge problem with my state change event firing a later
mouse click event. I have a button that when clicked it calls a method
(play()) that adds a state changed listener and changes the state. The
state changed listener then calls a method readyGame() and adds a
mouse listener. The problem is that the mouse even is fired right
after the state changed event, without any user input.

Can anyone help me figure out what the event stack is doing and how I
can fix this?

<mx:SetEventHandler target="{BtnMulitplayer}" name="click"
handler="play()"/>

private function play():void {
    addEventListener(StateChangeEvent.CURRENT_STATE_CHANGE,
stateChangeHandler);
    currentState = "GameState";
}
private function stateChangeHandler(event:StateChangeEvent):void {
    if (event.newState == "GameState") {
        readyGame();
        PhaseText.text = "Click to start game.";
        addEventListener(MouseEvent.CLICK, startGame);
    } else if (event.oldState == "GameState") {
        removeEventListener(StateChangeEvent.CURRENT_STATE_CHANGE,
stateChangeHandler);
    }
}


Reply via email to