Search code examples
apache-flexstates

get state before currentstate in flex


I have five states in flex and change between them randomly.

How to get information about previous state (the active state before currentState) in flex?


Solution

  • Add a listener to the state changing event of your object and save the current state to a variable.

    This could look like the following:

    <fx:Script>
        <![CDATA[
    
            private var previousState : String;
    
            protected function onCreationComplete($event : FlexEvent) : void
            {
                        yourObject.addEventListener(StateChangeEvent.CURRENT_STATE_CHANGING,
                                 onChangingState);
            }
    
    
            protected function onChangingState($event : StateChangeEvent) : void
            {
                        previousState = $event.oldState;
            }