Events, messages, and handlers
35
•
It must consist of one word or of several words connected by an underscore—no spaces
are allowed.
•
It must be different from the name of any predefined Lingo or JavaScript syntax element.
Using predefined Lingo or JavaScript keywords for message and handler names can create
confusion. Although it is possible to explicitly replace or extend the functionality of a Lingo or
JavaScript element by using it as a message or handler name, this should be done only in certain
advanced situations.
When you have multiple handlers with similar functions, it is useful to give them names that have
similar beginnings so they appear together in an alphabetical listing, such as the listing that can be
displayed by the Edit > Find > Handler command.
Handlers
A handler is a set of statements within a script that runs in response to a specific event and
subsequent message. Although Director contains built-in events and messages, you must create
your own custom handlers for each event/message pair that you want to handle.
Deciding where to place handlers
You can place handlers in any type of script, and a script can contain multiple handlers. It’s a good
idea to group related handlers in a single place, though, for easier maintenance.
The following are some useful guidelines for many common situations:
•
To associate a handler with a specific sprite, or to have a handler run in response to an action
on a specific sprite, put the handler in a behavior attached to the sprite.
•
To set up a handler that should be available any time the movie is in a specific frame, put the
handler in a behavior attached to the frame.
For example, to have a handler respond to a mouse click while the playhead is in a frame,
regardless of where the click occurs, place a
mouseDown
or
mouseUp
handler in the frame
behavior rather than in a sprite behavior.
•
To set up a handler that runs in response to messages about events anywhere in the movie, put
the handler in a movie script.
•
To set up a handler that runs in response to an event that affects a cast member, regardless of
which sprites use the cast member, put the handler in a cast member script.
Determining when handlers receive a message
After sending a message to scripts, Director checks for handlers in a definite order.
1
Director first checks whether a handler exists in the object from which the message was sent. If
a handler is found, the message is intercepted, and the script in the handler runs.
2
If no handler is found, Director then checks cast member, in ascending order, for any associated
movie scripts that might contain a handler for the message. If a handler is found, the message is
intercepted, and the script in the handler runs.
3
If no handler is found, Director then checks whether a frame script contains a handler for the
message. If a handler is found, the message is intercepted, and the script in the handler runs.
4
If no handler is found, Director then checks sprites, in ascending order, for any scripts
associated with the sprites that might contain a handler for the message. If a handler is found,
the message is intercepted, and the script in the handler runs.
Summary of Contents for DIRECTOR MX 2004
Page 1: ...DIRECTOR MX 2004 Director Scripting Reference...
Page 48: ...48 Chapter 2 Director Scripting Essentials...
Page 100: ...100 Chapter 4 Debugging Scripts in Director...
Page 118: ...118 Chapter 5 Director Core Objects...
Page 594: ...594 Chapter 12 Methods...
Page 684: ...684 Chapter 14 Properties See also DVD...
Page 702: ...702 Chapter 14 Properties See also face vertices vertices flat...
Page 856: ...856 Chapter 14 Properties JavaScript syntax sprite 15 member member 3 4...
Page 1102: ...1102 Chapter 14 Properties...