Using Handlers - MACROMEDIA DIRECTOR MX-USING DIRECTOR MX Use Manual

Table of Contents

Advertisement

Using handlers

As described in "Using messages to identify events" on page 394, Director sends messages to
handlers within scripts when specific events occur. You attach a set of handlers to an object by
attaching the handlers' script to the object. See "Creating and attaching scripts with the
Script window" on page 412.
Each handler begins with the word
to. The last line of the handler is the word
this is optional.
When an object receives a message that corresponds to a handler attached to the object, Director
runs the Lingo statements within the handler. For example, the
the user clicked the mouse button. To indicate in your script that an action should be performed
when the mouse is clicked, you include a line in your script that begins with
follow this line with the Lingo statements that should execute when the script receives the
message.
mouseDown
Using arguments to pass values to a handler
By using arguments for values, you can give the handler exactly the values that it needs to use at a
specific time, regardless of where or when you call the handler in the movie. Arguments can be
optional or required, depending on the situation.
To create arguments for a handler:
Put the arguments after the handler name. Use commas to separate multiple arguments.
For example, the following handler, called
and
, stores the result in local variable
b
to the original handler:
on addThem a, b
-- a and b are argument placeholders
c = a + b
return c
end
When you call a handler, you must provide specific values for the arguments that the handler
uses. You can use any type of value, such as a number, a variable that has a value assigned, or a
string of characters. Values in the calling statement must be in the order they follow in the
handler's arguments, and they must be surrounded by parentheses.
The following statement is a calling statement for the
set mySum = addThem(4, 8)
Because
is first in the list of arguments, Lingo substitutes it for
4
because
is second in the list of arguments, Lingo substitutes
8
After the calling statement sends these parameters to the handler, the handler returns the value
which corresponds to the variable
calling statement is then set to
You can also use expressions as values. For example, the following statement substitutes
and
(or
, representing
8>2
1
set mySum = addThem(3+6, 8>2)
396
Chapter 16
followed by the message that the handler should respond
on
. You can repeat the handler's name after
end
addThem
, and uses the Lingo term
c
inside the
c
on addThem
.
12
) for
, and would return
TRUE
b
mouseDown
, adds two values it receives in the arguments
return
handler:
on addThem
in the handler. Likewise,
a
for
everywhere in the handler.
8
b
handler. The variable
:
10
, but
end
message indicates that
. You
onMouseDown
a
to send the result back
,
12
in the
mySum
for
3+6
a

Advertisement

Table of Contents
loading

This manual is also suitable for:

Director mx

Table of Contents