Using Event Handler Methods - MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

For more information on handling events, see the following sections:
Using event handler methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
Using event listeners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .332
Using event listeners with components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .335
Using button and movie clip event handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
Broadcasting events from component instances . . . . . . . . . . . . . . . . . . . . . . . . . . . .342
Creating movie clips with button states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .342
Event handler scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .343
Scope of the this keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
Using the Delegate class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347

Using event handler methods

An event handler method is a method of a class that is invoked when an event occurs on an
instance of that class. For example, the MovieClip class defines an
event handler that
onPress
is invoked whenever the mouse is pressed on a movie clip object. Unlike other methods of a
class, however, you don't invoke an event handler directly; Flash Player invokes it
automatically when the appropriate event occurs.
The following ActionScript classes are examples of classes that define event handlers: Button,
ContextMenu, ContextMenuItem, Key, LoadVars, LocalConnection, Mouse, MovieClip,
MovieClipLoader, Selection, SharedObject, Sound, Stage, TextField, XML and XMLSocket.
For more information about the event handlers they provide, see the entries for each class
in ActionScript 2.0 Language Reference. The word handler is added in the title of each
event handler.
By default, event handler methods are undefined: when a particular event occurs, its
corresponding event handler is invoked, but your application doesn't respond further to the
event. To have your application respond to the event, you define a function with the function
statement and then assign that function to the appropriate event handler. The function you
assign to the event handler is then automatically invoked whenever the event occurs.
An event handler consists of three parts: the object to which the event applies, the name of the
object's event handler method, and the function you assign to the event handler. The
following example shows the basic structure of an event handler:
object.eventMethod = function () {
// Your code here, responding to event.
}
330
Handling Events

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash 8

Table of Contents