【发布时间】:2010-12-22 14:21:06
【问题描述】:
对于我的自定义组件,当它们从启用到禁用或禁用到启用时,我想触发一个自定义事件。 我在 livedocs 中找不到任何相关事件。 请问有什么线索吗?
【问题讨论】:
标签: apache-flex actionscript-3 mxml
对于我的自定义组件,当它们从启用到禁用或禁用到启用时,我想触发一个自定义事件。 我在 livedocs 中找不到任何相关事件。 请问有什么线索吗?
【问题讨论】:
标签: apache-flex actionscript-3 mxml
如果它们是自定义组件,并且我假设您正在扩展 UIComponent(或子类),为什么不直接覆盖 Enabled setter 方法,然后在其中调度自定义事件?
类似:
override public function set enabled(value:Boolean):void {
super.enabled = value;
dispatchEvent(new EnabledChangedEvent());
}
【讨论】:
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);
【讨论】: