I am a new Flex coder. So far I'm enjoying the flexibility of the framework,
but I am having a heck of a time with state changes. I'm using Flex 4.1. I'm
working on a basic GUI. You start with a welcome screen, followed by a state
change to a login screen, and a state change to a chat lobby. When the lobby is
displayed, there's a bunch of initialization that needs to happen. If the user
navigates away from this state/view, then they should be automatically
disconnected from the chat server and be brought back to the beginning. The
problem is, I cannot for the life of me get anything to trigger using
enterState and exitState. Even currentStateChanging appears to not be
triggered. I can make the init happen the first time using creationComplete,
but that's it. I am wondering if my using a custom event handler is causing
trouble.
Each of the different views are a custom component. Each component has the
following declaration in the Metadata:
[Event(name="stateChangeEvent", type="events.MyStateChangeEvent")]
MyStateChangeEvent allows the components to pass the desired state to the main
application which then initiates the switch. The individual components are
called as follows in the main application:
<components:WelcomeScreen x="0" y="0" includeIn="Welcome"
stateChangeEvent="stateChangeEventHandler(event)">
</components:WelcomeScreen>
The event handler is pretty basic:
protected function stateChangeEventHandler(event:MyStateChangeEvent):void
{
this.currentState = event.stateChangeData.newState.toString();
}
Is the custom handler what's causing the trouble? If so, how do I pass data
between components via events yet still take advantage of the enterState and
exitState triggers?
I sincerely appreciate your time and patience.
Aaron