O'Reilly logo

Essential ActionScript 3.0 by Colin Moock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Type Weakness in ActionScript's Event Architecture

ActionScript's listener-based event architecture involves many different participants—the event listener, the object that registers the listener, the event target, the event object, and the event name. A given event dispatch (and response) succeeds only when those participants interoperate properly. In order for the participants to interoperate properly, the following basic assumptions must be met:

  • The event type for which the listener registered must exist

  • The listener, itself, must exist

  • The listener must know how to handle the event object dispatched when the event occurs

  • The object that registered the listener must support the specified event type

When a listener registers with an object for an event, it enters into a datatype-based contract that guarantees the first three of the preceding four assumptions. If that contract is not upheld, ActionScript generates a datatype error. For example, consider the following event-listener registration and definition code, which includes three intentional event-listener-contract violations (shown in bold):

urlLoader.addEventListener(Event.COMPLTE,completeListenr);

private function completeListener (e:MouseEvent):void {
  trace("Load complete");
}

The event-listener contract violations in the preceding code are as follows:

  • The constant Event.COMPLTE has a typo: it is missing an "E." ActionScript generates an error warning the programmer that the event type for which the listener is attempting to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required