Search code examples
flashapache-flexflex4

Is there a method in UIComponent that tells when a state change happens?


I'm working an a custom component and I need to be able to tell when a state changes.

Is adding an event listener for StateChangeEvent.CURRENT_STATE_CHANGE the only way to listen for a state change or is there a method I can override?

public function MyComponent() extends SkinnableComponent {

    public function MyComponent() {
        addEventListener(StateChangeEvent.CURRENT_STATE_CHANGE, onCurrentStateChange);
    }

    private function onCurrentStateChange(event:StateChangeEvent):void {
        //invalidateSkinState();
    }
}

I looked at UIComponent.commitCurrentState() (where the event is dispatched) and it's marked private.


Solution

  • You can override:

    protected function stateChanged(oldState:String, newState:String, recursive:Boolean):void

    And you have other events like enterState:

    Dispatched after the component has entered a view state.

    stateChangeComplete:

    Dispatched after the component has entered a new state and any state transition animation to that state has finished playing. The event is dispatched immediately if there's no transition playing between the states. If the component switches to a different state while the transition is underway, this event will be dispatched after the component completes the transition to that new state.