Chapter 12. Events and Event Handling

In general terms, an event is a noteworthy runtime occurrence that has the potential to trigger a response in a program. In ActionScript, events can be broken into two categories: built-in events, which describe changes to the state of the runtime environment, and custom events, which describe changes to the state of a program. For example, a built-in event might be the clicking of the mouse or the completion of a file-load operation. By contrast, a custom event might be the ending of a game or the submission of an answer in a quiz.

Events are ubiquitous in ActionScript. In fact, in a pure ActionScript program, once the main-class constructor method has finished executing, all subsequent code is triggered by events. Accordingly, ActionScript supports a rich event architecture that provides the foundation for both built-in and custom events.

Tip

ActionScript’s event architecture is based on the W3C Document Object Model (DOM) Level 3 Events Specification, available at http://www.w3.org/TR/DOM-Level-3-Events.

This chapter teaches the fundamentals of ActionScript’s event architecture, covering both how to respond to built-in events and how to implement custom events in an ActionScript program. Note, however, that this chapter covers event fundamentals only. Later, inChapter 21, we’ll study how ActionScript’s event architecture caters to display objects (objects that represent onscreen content). Then, in Chapter 22, we’ll examine a variety of specific ...

Get Essential ActionScript 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.