3

For my custom components, when they go from enabled to disabled or disabled to enabled, I want to trigger a custom event. I can't find any related events in the livedocs. Any clues please?

CodeQrius
  • 429
  • 1
  • 7
  • 23

2 Answers2

5

UIComponent does dispatch an event of type enabledChanged from its set enabled method. Here is the source of that method:

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"));
}

You can listen to it using:

myComponent.addEventListener("enabledChanged", handleEnabledChanged);
Amarghosh
  • 58,710
  • 11
  • 92
  • 121
1

If they're custom components, and I'm assuming you're extending UIComponent (or a child class), why don't you just override the Enabled setter method, then dispatch a custom event within that?

Something like:

override public function set enabled(value:Boolean):void {
   super.enabled = value;
   dispatchEvent(new EnabledChangedEvent());
}
LJW
  • 2,378
  • 1
  • 21
  • 35