For example, consider that you wrote a custom sprite method named
integer as a parameter, and you placed the method in a behavior. When you call
sprite object reference, the handler must also include a parameter that represents the script object
reference, and not just the single integer. In this case, the implied parameter is represented by the
keyword
, but any term will work.
me
-- Lingo syntax
myHeight = sprite(2).jump(5)
on jump(me,a)
return a + 15 -- this handler works correctly, and returns 20
end
on jump(a)
return a + 15 -- this handler does not work correctly, and returns 0
end
You can also use expressions as values. For example, the following statement substitutes
and
(or
, representing
8>2
1
-- Lingo syntax
mySum = addThem(3+6, 8>2)
In Lingo, each handler begins with the word
respond to. The last line of the handler is the word
, but this is optional.
end
In JavaScript syntax, each handler begins with the word
the handler should respond to. The statements that comprise the handler are surrounded by
opening and closing brackets, as are all JavaScript syntax functions.
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 keyword
example, the following
-- Lingo syntax
on findColor
return sprite(1).foreColor
end
// JavaScript syntax
function findColor() {
return(sprite(1).foreColor);
}
You can also use the keyword
value. For example, the following
otherwise, it returns a value.
-- Lingo syntax
on jump(aVal)
if aVal = 5 then return
aVal = aVal + 10
return aVal
end
) for
, and would return
TRUE
b
to have a handler report a condition or the result of an action. For
return
handler returns the current color of sprite 1:
findColor
by itself to exit from the current handler and return no
return
handler returns nothing if the
jump
:
10
followed by the message that the handler should
on
. You can repeat the handler's name after
end
followed by the message that
function
Events, messages, and handlers
that takes a single
jump()
from a
jump()
3+6
parameter equals 5;
aVal
for
a
37
Need help?
Do you have a question about the DIRECTOR MX 2004-DIRECTOR SCRIPTING and is the answer not in the manual?
Questions and answers