Features

robertpenner edited this page Sep 13, 2010 · 11 revisions

Signals have many features not available from Flash’s EventDispatcher.

  • Remove all event listeners:
    signal.removeAll();
    
  • Retrieve the number of listeners:
    trace( signal.numListeners );
    
  • Listeners can be added for a one-time call and removed automatically on dispatch:
    signal.addOnce(theListener); // result: signal has one listener
    signal.dispatch(theEvent);   // result: theListener is called, signal now has no listeners
    
  • Any object type can be dispatched to listeners; no flash.events.Event restriction.
  • You can dispatch your value objects themselves and avoid creating so many Event subclasses.
  • Any number of arguments can be dispatched to listeners, from zero to many.
  • A Signal can be initialized with value classes that will validate value objects on dispatch (optional):
    // A Signal that will dispatch a String and an integer:
    progress = new Signal(String, int);
    //later:
    progress.dispatch(); // will throw ArgumentError 
    progress.dispatch('The Answer'); // will throw ArgumentError 
    progress.dispatch('The Answer', 42.5); // will throw ArgumentError 
    progress.dispatch('The Answer', 42); // will succeed
    
  • If the Signal has any value classes specified, each listener is checked on `add()` to ensure it declares enough arguments for the value objects.
  • Signals can be placed in interfaces to indicate the events dispatched by a class.
  • Events can bubble recursively through `.parent` independent of the display list (experimental).
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.