MACROMEDIA DIRECTOR MX-USING DIRECTOR MX Use Manual page 397

Table of Contents

Advertisement

Returning results from handlers
Often you want a handler to report some condition or the result of some action.
To return results from a handler:
Use the
return
example, the following handler returns the current color of sprite 1:
on findColor
return sprite(1).foreColor
end
When you define a handler that returns a result, you must use parentheses after the handler when
you call it from another handler. For example, the statement
handler and then displays the result in the Message window.
findColor
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 set up a handler that affects a specific sprite or runs 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 an
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
A movie can contain more than one handler for the same message. Director manages this
situation by sending the message to objects in a definite order.
The general order in which messages are sent to objects is as follows:
Messages are sent first to behaviors attached to a sprite involved in the event. If a sprite has
1
more than one behavior attached to it, behaviors respond to the message in the order in which
they are attached to the sprite.
Messages are sent next to a script attached to the cast member assigned to the sprite.
2
Messages are then sent to behaviors attached to the current frame.
3
Messages are sent last to movie scripts.
4
When a message reaches a script that contains a handler corresponding to the message, Director
executes the handler's instructions.
function to have a handler report a condition or the result of an action. For
put findColor()
or
on mouseDown
on mouseUp
Writing Scripts with Lingo 397
calls the
on
handler in the

Advertisement

Table of Contents
loading

This manual is also suitable for:

Director mx

Table of Contents