UIComponent 中是否有一种方法可以告知何时发生状态更改?

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

我正在开发一个自定义组件,我需要能够判断状态何时发生变化。

StateChangeEvent.CURRENT_STATE_CHANGE 添加事件侦听器是侦听状态更改的唯一方法吗?还是有我可以覆盖的方法?

public function MyComponent() extends SkinnableComponent {

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

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

我查看了 UIComponent.commitCurrentState()(调度事件的地方),它被标记为私有。

好像有UIComponent.stageChanged()方法可以扩展:

This method is called when a state changes to check whether state-specific styles apply to this component. If there is a chance of a matching CSS pseudo-selector for the current state, the style cache needs to be regenerated for this instance and, potentially all children, if the recursive param is set to true.

作为:

protected function stateChanged(oldState:String, newState:String, recursive:Boolean):void
{
    // This test only checks for pseudo conditions on the subject of the selector.
    // Pseudo conditions on ancestor selectors are not detected - eg:
    //    List ScrollBar:inactive #track
    // The track styles will not change when the scrollbar is in the inactive state.
    if (currentCSSState && oldState != newState &&
           (styleManager.hasPseudoCondition(oldState) ||
            styleManager.hasPseudoCondition(newState)))
    {
        regenerateStyleCache(recursive);
        initThemeColor();
        styleChanged(null);
        notifyStyleChangeInChildren(null, recursive);
    }
}

您可以覆盖:

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

你还有其他活动,例如 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.