Chapter 20. Events and the Event Flow
ActionScript 3.0 uses a powerful framework for handling internal communication known as the event framework. Events are messages that are sent between objects when an action, such as a button click, has taken place. This enables you to create functionality that occurs interactively and without the need for direct method calls to other classes.
The Flash Player API uses events for many purposes in a unified way. Events handle mouse actions, timers, networking, and asynchronous errors. In this chapter you'll learn about how these subsystems use the event framework.
I'll take a look at how
EventDispatcher objects communicate and how the new
Event objects are structured. I'll also check out some of the more advanced features of the event framework, including how to create your own custom events and how to use event bubbling.
What exactly is an event? At its core, an event is an object that represents an occurrence and describes the conditions surrounding that occurrence. This includes (but is not limited to) a description of the event, called the event type, and the origin of the event, also known as the event target.
Events — and the Observer design pattern that the event framework follows — allow one object, called an event dispatcher, to trigger the actions of one or more other objects, called event listeners, without having to know anything about the structure of the other objects. Because the object broadcasting the event doesn't ...