![MACROMEDIA DIRECTOR MX 2004-DIRECTOR SCRIPTING Reference Download Page 22](http://html1.mh-extra.com/html/macromedia/director-mx-2004-director-scripting/director-mx-2004-director-scripting_reference_3321720022.webp)
22
Chapter 2: Director Scripting Essentials
To assign a value to a variable:
•
Use the equals (
=
) operator.
For example, the following statement assigns a URL to the variable
placesToGo
:
// JavaScript syntax
var placesToGo = "http://www.macromedia.com";
Variables can also hold the results of mathematical operations. For example, the following
statement adds the result of an addition operation to the variable
mySum
:
-- Lingo syntax
mySum = 5 + 5 -- this sets mySum equal to 10
As another example, the following statement returns the cast member assigned to sprite 2 by
retrieving the value of the sprite’s
member
property and places it into the variable
textMember
.
-- Lingo syntax
textMember = sprite(2).member
It is good practice to use variable names that indicate what the variable is used for. This makes
your scripts easier to read. For example, the variable
mySum
indicates that the variable contains a
sum of numbers.
To test the values of properties or variables:
•
Use the
put()
or the
trace()
functions in the Message window or check the values in the
Watcher window; (
put()
and
trace()
provide identical functionality and are available to
both Lingo and JavaScript syntax).
For example, the following statement displays the value assigned to the variable
myNumber
in the
Message window.
-- Lingo syntax
myNumber = 20 * 7
put(myNumber) -- displays 140 in the Message window
// JavaScript syntax
var myNumber = 20 * 7;
trace(myNumber) // displays 140 in the Message window
Using global variables
Global variables can be shared among handlers, scripts, or movies. A global variable exists and
retains its value as long as Director is running or until you call the
clearGlobals()
method.
In Macromedia Shockwave Player, global variables persist among movies displayed by the
goToNetMovie()
method, but not among those displayed by the
goToNetPage()
method.
Every handler that declares a variable as global can use the variable’s current value. If the handler
changes the variable’s value, the new value is available to every other handler that treats the
variable as global.
It is good practice to start the names of all global variables with a lowercase
g
. This helps identify
which variables are global when you examine your code.
Director provides a way to display all current global variables and their current values and to clear
the values of all global variables.
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...