30
Chapter 2: Director Scripting Essentials
When writing
if...then
structures in Lingo, you can place the statement or statements
following
then
in the same line as
then
, or you can place them on their own line by inserting a
carriage return after
then
. If you insert a carriage return, you must also include an
end if
statement at the end of the
if...then
structure.
When writing
if
structures in JavaScript syntax, you can place the statement or statements
following
if
in the same line as
if
, or you can place them on their own line by inserting a
carriage return after
if
.
For example, the following statements are equivalent:
-- Lingo syntax
if _mouse.mouseMember = member(1) then _movie.go("Cairo")
if _mouse.mouseMember = member(1) then
_movie.go("Cairo")
end if
// JavaScript syntax
if (_mouse.mouseMember = member(1)) { _movie.go("Cairo"); }
if (_mouse.mouseMember = member(1)) {
_movie.go("Cairo");
}
For reference information on using the
if...then...else
and
if...else
structures, see
“if ”
on page 209
.
Evaluating and matching expressions
The
case
(Lingo) or
switch...case
(JavaScript syntax) structures are shorthand alternatives to
using
if...then...else
or
if...then
structures when setting up multiple branching
structures. The
case
and
switch...case
structures are often more efficient and easier to read
than many
if...then...else
or
if...then
structures.
In Lingo, the condition to test for follows the term
case
in the first line of the
case
structure.
The comparison goes through each line in order until Lingo encounters an expression that
matches the test condition. When a matching expression is found, Director executes the Lingo
that follows the matching expression.
In JavaScript syntax, the condition to test for follows the term
switch
in the first line of the
structure. Each comparison in the test follows the term
case
for each line that contains a test.
Each
case
comparison can be ended by using the optional term
break
. Including the term
break
breaks the program out of the
switch
structure and executes any statements following the
structure. If
break
is omitted, the following
case
comparison is executed.
A
case
or
switch...case
structure can use comparisons as the test condition.
For example, the following
case
and
switch...case
structures test which key the user pressed
most recently and responds accordingly.
•
If the user pressed A, the movie goes to the frame labeled Apple.
•
If the user pressed B or C, the movie performs the specified transition and then goes to the
frame labeled Oranges.
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...