Writing Scripts with Lingo
397
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
function to have a handler report a condition or the result of an action. For
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
put findColor()
calls the
on
findColor
handler and then displays the result in the Message window.
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
on mouseDown
or
on 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
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:
1
Messages are sent first to behaviors attached to a sprite involved in the event. If a sprite has
more than one behavior attached to it, behaviors respond to the message in the order in which
they are attached to the sprite.
2
Messages are sent next to a script attached to the cast member assigned to the sprite.
3
Messages are then sent to behaviors attached to the current frame.
4
Messages are sent last to movie scripts.
When a message reaches a script that contains a handler corresponding to the message, Director
executes the handler’s instructions.
Summary of Contents for DIRECTOR MX-USING DIRECTOR MX
Page 1: ...Using Director MX Macromedia Director MX...
Page 12: ...Contents 12...
Page 156: ...Chapter 4 156...
Page 202: ...Chapter 6 202...
Page 244: ...Chapter 7 244...
Page 292: ...Chapter 10 292...
Page 330: ...Chapter 12 330...
Page 356: ...Chapter 13 356...
Page 372: ...Chapter 14 372...
Page 442: ...Chapter 16 442...
Page 472: ...Chapter 18 472...
Page 520: ...Chapter 19 520...
Page 536: ...Chapter 20 536...
Page 562: ...Chapter 23 562...
Page 566: ...Chapter 24 566...
Page 602: ...Chapter 27 602...