O'Reilly logo

The ActionScript 3.0 Quick Reference Guide by Rich Shupe, Darren Richardson, David Stiller, Jen deHaan

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

Chapter 14. How Do I Work with Events?

14.0 Introduction

The new event model is one of the biggest changes ActionScript 3.0 introduces. Gone are the event handlers of prior versions, such as onRelease or the more antiquated on(release) handler applied directly to symbol instances. The new model makes use exclusively of event listeners. In simple terms, event listeners are established to monitor for the occurrence of a particular event, and then execute a function when that event is received. Since listeners are required for all event processing, this chapter both explains and uses them extensively.

Even if you have experience with event listeners from prior versions of ActionScript (perhaps from use with components or objects for capturing key events), the event flow is quite different in ActionScript 3.0. Events can cascade down through the display list and bubble back up to the root of the file, allowing for advanced event handling. In line with the focus of this quick answer guide, this chapter covers the basic essentials of event processing, but provides an adequate overview to get you started.

14.1 Understanding Event Listeners

Problem

You want to understand the basic operation of an event listener.

Solution

Create an event listener and accompanying function to execute when a desired event is received.

Discussion

The first part of reacting to an event is to create an event listener. You do this by using the addEventListener() method, attaching the listener to the object that will be ...

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