Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 348

Programming actionscript 3.0
Table of Contents

Advertisement

Unfortunately, the syntax used by the various event models overlap in various ways, and differ
in others. For example, in ActionScript 2.0, some properties, such as
,
TextField.onChanged
can be used as either a callback function or an event listener. However, the syntax for
registering listener objects differs depending on whether you are using one of the six classes
that support listeners or the UIEventDispatcher class. For the Key, Mouse, MovieClipLoader,
Selection, Stage, and TextField classes, you use the
method, but for
addListener()
components event handling, you use a method called
.
addEventListener()
Another complexity introduced by the different event handling models was that the scope of
the event handler function varied widely depending on the mechanism used. In other words,
the meaning of the
keyword was not consistent among the event handling systems.
this
Event handling in ActionScript 3.0
ActionScript 3.0 introduces a single event handling model that replaces the many different
event handling mechanisms that existed in previous versions of the language. The new event
model is based on the Document Object Model (DOM) Level 3 Events Specification.
Although the SWF file format does not adhere specifically to the Document Object Model
standard, there are sufficient similarities between the display list and the structure of the
DOM to make implementation of the DOM event model possible. An object on the display
list is analogous to a node in the DOM hierarchical structure, and the terms display list object
and node are used interchangeably throughout this discussion.
The Flash Player implementation of the DOM event model brings with it a new concept
named default behaviors. A default behavior is an action that Flash Player executes as the
normal consequence of certain events.
Default behaviors
Developers are usually responsible for writing code that responds to events. In some cases,
however, a behavior is so commonly associated with an event that Flash Player automatically
executes the behavior unless the developer adds code to cancel it. Because Flash Player
automatically exhibits the behavior, such behaviors are called default behaviors.
For example, when a user enters text into a TextField object, the expectation that the text will
be displayed in that TextField object is so common that the behavior is built into Flash Player.
If you do not want this default behavior to occur, you can cancel it using the new event
handling system. When a user inputs text into a TextField object, Flash Player creates an
instance of the TextEvent class to represent that user input. To prevent Flash Player from
displaying the text in the TextField object, you must access that specific TextEvent instance
and call that instance's
method.
preventDefault()
348
Handling Events

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents