Conditional constructs
31
•
If the user pressed any other letter key, the computer beeps.
-- Lingo syntax
case (_key.key) of
"a" : _movie.go("Apple")
"b", "c":
_movie.puppetTransition(99)
_movie.go("Oranges")
otherwise: _sound.beep()
end case
// JavaScript syntax
switch (_key.key) {
case "a" :
_movie.go("Apple");
break;
case "b":
_movie.puppetTransition(99);
_movie.go("Oranges");
break;
case "c":
_movie.puppetTransition(99);
_movie.go("Oranges");
break;
default: _sound.beep()
}
Note:
In JavaScript syntax, only one comparison can be made per
case
statement.
For reference information on using
case
structures, see
“case” on page 203
.
Repeating actions
In both Lingo and JavaScript syntax, you can repeat an action a specified number of times or
while a specific condition exists.
In Lingo, to repeat an action a specified number of times you use a
repeat with
structure.
Specify the number of times to repeat as a range following
repeat with
.
In JavaScript syntax, to repeat an action a specified number of times you use the
for
structure.
The
for
structure takes three parameters: the first parameter typically initializes a counter
variable, the second parameter specifies a condition to evaluate each time through the loop, and
the third parameter is typically used to update or increment the counter variable.
The
repeat with
and
for
structures are useful for performing the same operation on a series of
objects. For example, the following loop makes Background Transparent the ink for sprites 2
through 10:
-- Lingo syntax
repeat with n = 2 to 10
sprite(n).ink = 36
end repeat
// JavaScript syntax
for (var n=2; n<=10; n++) {
sprite(n).ink = 36;
}
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...