【问题标题】:Is there a method in UIComponent that tells when a state change happens?UIComponent 中是否有一个方法可以告知何时发生状态更改?
【发布时间】:2016-10-30 06:01:53
【问题描述】:

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

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()(发送事件的位置),它被标记为私有。

【问题讨论】:

    标签: flash apache-flex flex4


    【解决方案1】:

    您可以覆盖:

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

    您还有其他活动,例如enterState:

    在组件进入视图状态后调度。

    stateChangeComplete:

    在组件进入新状态和任何状态后调度 到该状态的过渡动画已播放完毕。该事件是 如果在 状态。如果组件切换到不同的状态,而 过渡正在进行中,此事件将在 组件完成向新状态的转换。

    【讨论】:

      【解决方案2】:

      貌似有UIComponent.stageChanged()方法可以扩展:

      当状态改变时调用该方法来检查是否 特定于状态的样式适用于此组件。如果有机会 当前状态的匹配 CSS 伪选择器的样式 需要为此实例重新生成缓存,并且可能所有 孩子,如果 recursive 参数设置为 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);
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-16
        • 2010-12-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多