MACROMEDIA DIRECTOR MX-USING DIRECTOR MX Use Manual page 402

Table of Contents

Advertisement

About variables
Director uses variables to store and update values. As the name implies, a variable contains a value
that can be changed or updated as the movie plays. By changing the value of a variable as the
movie plays, you can do things such as store a URL, track the number of times a user takes part in
an online chat session, or record whether a network operation is complete.
It's a good idea always to assign a variable a known value the first time you define the variable.
This is known as initializing a variable. Initializing variables makes it easier to track and compare
the variable's value as the movie plays.
Variables can be global or local. A global variable can exist and retain its value as long as Director
is running, including when a movie branches to another movie. A local variable exists only as long
as the handler in which it is defined is running. See "Using global variables" on page 403 and
"Using local variables" on page 404.
Storing and updating values in variables
Variables can hold any of the types of information found in Director: numbers, strings,
values, symbols, lists, or the result of a calculation. To store and retrieve the values of
FALSE
properties and variables, Lingo uses the equals (
Also, a variable in Lingo can contain different types of data at different times. (The ability to
change a variable's type distinguishes Lingo from other languages such as Java, in which a
variable's type cannot be changed.)
For example, the statement
assigned the variable an integer. If you subsequently use the statement
becomes a string variable, because the variable now contains a string.
You can convert a string to a number or a number to a string with the
functions. For example, the statement
The statement
x = string(1)
Some properties cannot be set, but can only be tested. Often these are properties that describe
some condition that exists outside the control of Director. For example, you cannot assign a value
to the
numChannels
Shockwave movie. However, you can retrieve the number of channels by referring to the
property of a cast member.
numChannels
To assign a value to a variable:
Use the equals (
at the beginning of the statement.
For example, any of these statements will change the cast member assigned to sprite 2 by setting
the sprite's
member
(see "Dot syntax" on page 393):
set the member of sprite 2 = member "Big Flash"
set sprite (2).member = member ("Big Flash")
sprite (2).member = member ("Big Flash")
As another example, each of these statements assigns a URL to the variable
placesToGo = "http://www.macromedia.com"
set placesToGo = "http://www.macromedia.com"
402
Chapter 16
creates the variable
x = 1
x = value("1")
stores the string "1" in the variable
cast member property, which indicates the number of channels within a
) operator. For improved readability, you can use the optional
=
property to a different cast member. The last two statements use dot syntax
) operator and the
=
set
, which is an integer variable because you
x
stores the number 1 in the variable
.
x
TRUE
and
commands.
put
, the variable
x = "one"
and
value()
string()
x
command
set
:
placesToGo
or
x
.

Advertisement

Table of Contents
loading

This manual is also suitable for:

Director mx

Table of Contents