addEventListener<T extends Event> method

StreamSubscription<T> addEventListener <T extends Event>(String eventType, EventListener<T> eventListener, { bool useCapture: false, int priority: 0 })

Adds an event listener to receive events.

This style of adding an event listener is used for an easy migration from legacy ActionScript3 code to Dart code. In pure Dart code you should consider using the Dart style of adding event listenes like this:

Example:

// ActionScript3 style
sprite.addEventListener(Event.ADDED_TO_STAGE, _onAddedToStage);
sprite.addEventListener(MouseEvent.Click, _onMouseClick, useCapture: true);
sprite.addEventListener("CustomEvent", _onCustomEvent);

// Dart style
sprite.onAddedToStage.listen(_onAddedToStage);
sprite.onMouseClick.capture(_onMouseClick);
sprite.on("CustomEvent").listen(_onCustomEvent);

Implementation

StreamSubscription<T> addEventListener<T extends Event>(
    String eventType, EventListener<T> eventListener,
    {bool useCapture = false, int priority = 0}) {
  var eventStream = this.on<T>(eventType);
  return eventStream._subscribe(eventListener, useCapture, priority);
}