36
Chapter 2: Director Scripting Essentials
After a handler intercepts a message, the message does not automatically pass on to the remaining
locations. However, in Lingo you can use the
pass()
method to override this default rule and
pass the message to other objects.
If no matching handler is found after the message passes to all possible locations, Director ignores
the message.
The exact order of objects to which Director sends a message depends on the message. For
information on the sequence of objects to which Director sends specific messages, see the entry
for each message in
Chapter 10, “Events and Messages,” on page 159
.
Using parameters to pass values to a handler
By using parameters 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. Parameters can be
optional or required, depending on the situation.
To create parameters for a handler:
•
In Lingo, put the parameters after the handler name. In JavaScript syntax, put the parameters
within parentheses, and then put them after the handler name. Use commas to separate
multiple parameters.
When you call a handler, you must provide specific values for the parameters 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 that they follow in the
handler’s parameters, and they must be surrounded by parentheses.
In the following example, the variable assignment
mySum
calls the method
addThem
, which is
passed the two values 2 and 4. The
addThem
handler replaces the parameter placeholders
a
and
b
with the two values passed to it, stores the result in the local variable
c
, and then uses the keyword
return
to send the result back to the original method, which is then assigned to
mySum
.
Because 2 is first in the list of parameters, it is substituted for
a
in the handler. Likewise, because 4
is second in the list of parameters, it is substituted for
b
in the handler.
-- Lingo syntax
mySum = addThem(2, 4) -- calling statement
on addThem a, b -- handler
c = a + b
return c -- returns the result to the calling statement
end
// JavaScript syntax
var mySum = addThem(2, 4); // calling statement
function addThem(a, b) { // handler
c = a + b;
return c; // returns the result to the calling statement
}
In Lingo, when you call a custom method from an object, a reference to the script object in
memory is always passed as an implied first parameter to the handler for that method. This means
that you must account for the script object reference in your handler.
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...