Events and event handlers

Flash MX introduced many important changes in ActionScript—changes and improvements that were
largely responsible for catapulting Flash into the serious Rich Internet Application forefront. One of
the biggest changes was the new event architecture that made programming very complex behaviors
far easier than was possible in earlier versions.
I’ve already talked a little about events, which occur when something happens in the system or the
user does something with the keyboard or mouse. Prior to Flash MX, the only real way to capture
these events was with an onClipEvent(eventName) or on(eventName) block on a movie clip or button.
This meant that you had to place a movie clip on stage at author time and write the code on it.
Although various workarounds were discovered, none was really optimal. The MX event architecture
wasn’t perfect, but it was a vast improvement on previous versions and allowed you to access events
from anywhere in your application, stop handling any particular event at any time, or change an
event’s behavior dynamically. You can imagine how much more power and flexibility that functionality
provided.
With Flash MX 2004, even more enhancements were made to the event architecture within the
included component framework. However, these enhancements were actually just built on top of
the existing event architecture via additional AS 2 classes. These classes provided a lot of additional
event handling power, but the underlying architecture still suffered from certain inadequacies that the
classes attempted to provide workarounds for.
In AS 3, the event architecture has been rewritten from the ground up. It is fast, powerful, and fully
integrated into Flash Player.
To understand events, you should understand a couple of additional concepts: listeners and handlers.
Listeners and handlers are actually well-named entities, because that’s exactly what they do. A listener
is an object that listens for events. A handler is a function that handles the event when it occurs.
Listeners and handlers have been implemented quite differently throughout the history of ActionScript,
and they’ve even had different implementations within AS 2. To avoid confusion, I’m going to stick
with AS 3, which has simplified the whole system, and made it nice and consistent.