Looks like you're adding the click handler to the entire
document/application.

 

Most mouse events bubble, so if you add a listener to the parent in your
handler it will see it after you handle it.

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Ashley
Sent: Monday, November 05, 2007 1:49 PM
To: [email protected]
Subject: [flexcoders] Event issue. Please help.

 

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