Scripting syntax
13
•
Parentheses are required after all method and function names. For example, when calling the
Sound object’s
beep()
method, you must include the parentheses after the word beep.
Otherwise, a script error will occur.
// JavaScript syntax
_sound.beep(); // this statement will work properly
_sound.beep; // this statement will result in a script error
When you call a method, function, or handler from within another method, function, or
handler, you must include parentheses in the calling statement. In the following example, the
modifySprite()
method contains a call to a
spriteClicked
handler. The call to the
spriteClicked
handler must include parentheses; otherwise, a script error occurs.
// JavaScript syntax
function modifySprite() {
spriteClicked(); // this call to the handler will work properly
spriteClicked; // this call to the handler results in a script error
}
function spriteClicked() {
// handler code here
}
You can also use parentheses to override the order of precedence in math operations, or to
make your statements easier to read. For example, the first math expression below yields a
result of 13, while the second expression yields a result of 5:
5 * 3 - 2 -- yields 13
5 * (3 - 2) -- yields 5
•
Event handler syntax varies between Lingo and JavaScript syntax. In Lingo, handlers use the
syntax
on
handlerName
. In JavaScript syntax, handlers are implemented as functions, and use
the syntax
function
handlerName
()
. For example, the following statements comprise a
handler that plays a beep when the mouse button is clicked:
-- Lingo syntax
on mouseDown
_sound.beep()
end
// JavaScript syntax
function mouseDown() {
_sound.beep();
}
•
Event handler parameter syntax can vary between Lingo and JavaScript syntax. Both Lingo and
JavaScript syntax support enclosing parameters passed to a handler within parentheses. If more
than one parameter is passed, each parameter is separated by a comma. In Lingo, you can also
pass parameters that are not enclosed by parentheses. For example, the following
addThem
handler receives the two parameters
a
and
b
.
-- Lingo syntax
on addThem a, b -- without parentheses
c = a + b
end
on addThem(a, b) -- with parentheses
c = a + b
end
// JavaScript syntax
function addThem(a, b) {
c = a + b;
}
Содержание DIRECTOR MX 2004-DIRECTOR SCRIPTING
Страница 1: ...DIRECTOR MX 2004 Director Scripting Reference...
Страница 48: ...48 Chapter 2 Director Scripting Essentials...
Страница 100: ...100 Chapter 4 Debugging Scripts in Director...
Страница 118: ...118 Chapter 5 Director Core Objects...
Страница 594: ...594 Chapter 12 Methods...
Страница 684: ...684 Chapter 14 Properties See also DVD...
Страница 702: ...702 Chapter 14 Properties See also face vertices vertices flat...
Страница 856: ...856 Chapter 14 Properties JavaScript syntax sprite 15 member member 3 4...
Страница 889: ...netPresent 889 _player alert Sorry the Network Support Xtras could not be found See also Player...
Страница 1102: ...1102 Chapter 14 Properties...