32
Chapter 2: Director Scripting Essentials
The following example performs a similar action, but with decreasing numbers:
-- Lingo syntax
repeat with n = 10 down to 2
sprite(n).ink = 36
end repeat
// JavaScript syntax
for (var n=10; n>=2; n--) {
sprite(n).ink = 36;
}
In Lingo, to repeat a set of instructions as long as a specific condition exists, use the
repeat
while
structure.
In JavaScript syntax, to repeat a set of instructions as long as a specific condition exists, use the
while
structure.
For example, the following statements instruct a movie to beep continuously whenever the mouse
button is being pressed:
-- Lingo syntax
repeat while _mouse.mouseDown
_sound.beep()
end repeat
// JavaScript syntax
while (_mouse.mouseDown) {
_sound.beep();
}
Both Lingo and JavaScript syntax scripts continue to loop through the statements inside the loop
until the condition is no longer true, or until one of the statements sends the script outside the
loop. In the previous example, the script exits the loop when the mouse button is released because
the
mouseDown
condition is no longer true.
In Lingo, to exit a loop, use the
exit repeat
statement.
In JavaScript syntax, to exit a loop you can use the term
break
. A loop also automatically exits
when a condition is no longer true.
For example, the following statements make a movie beep while the mouse button is pressed,
unless the mouse pointer is over sprite 1. If the pointer is over sprite 1, the script exits the
loop and stops beeping. The
rollover()
method indicates whether the pointer is over the
specified sprite.
-- Lingo syntax
repeat while _mouse.stillDown
_sound.beep()
if _movie.rollOver(1) then exit repeat
end repeat
// JavaScript syntax
while (_mouse.stillDown) {
_sound.beep();
if (_movie.rollOver(1)) {
break;
}
}
For reference information on the
repeat while
and
while
structures, see
“repeat while”
on page 220
.
Summary of Contents for DIRECTOR MX 2004-DIRECTOR SCRIPTING
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...