【问题标题】:Listening for enable/disable state change监听启用/禁用状态变化
【发布时间】:2010-12-22 14:21:06
【问题描述】:

对于我的自定义组件,当它们从启用到禁用或禁用到启用时,我想触发一个自定义事件。 我在 livedocs 中找不到任何相关事件。 请问有什么线索吗?

【问题讨论】:

    标签: apache-flex actionscript-3 mxml


    【解决方案1】:

    如果它们是自定义组件,并且我假设您正在扩展 UIComponent(或子类),为什么不直接覆盖 Enabled setter 方法,然后在其中调度自定义事件?

    类似:

    override public function set enabled(value:Boolean):void {
       super.enabled = value;
       dispatchEvent(new EnabledChangedEvent());
    }
    

    【讨论】:

      【解决方案2】:

      UIComponent 确实从其set enabled 方法中调度了enabledChanged 类型的事件。这是该方法的来源:

      public function set enabled(value:Boolean):void
      {
          _enabled = value;
      
          // Need to flush the cached TextFormat
          // so it recalcs with the disabled color,
          cachedTextFormat = null;
      
          invalidateDisplayList();
      
          dispatchEvent(new Event("enabledChanged"));
      }
      

      您可以使用以下方式收听:

      myComponent.addEventListener("enabledChanged", handleEnabledChanged);
      

      【讨论】:

        猜你喜欢
        • 2021-06-16
        • 2017-05-31
        • 2021-02-17
        • 2011-01-31
        • 2019-08-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-23
        相关资源
        最近更新 更多