
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
38
Chapter 2
CHAPTER 2
Variables
In a typical scripted movie, we have to track and manipulate everything from frame
numbers to a user’s password to the velocity of a photon torpedo fired from a space-
ship. In order to manage and retrieve all that information, we need to store it in vari-
ables, the primary information-storage containers of ActionScript.
A variable is like a bank account that, instead of holding money, holds information
(data). Creating a new variable is like setting up a new account; we establish a place
to store something we’ll need in the future. And, just as every bank account has an
account number, every variable has a name associated with it that is used to access
the data in the variable.
Once a variable is created, we can put new data into it as often as we want—much
like depositing money into an account. Or, we can find out what’s in a variable by
using the variable’s name—much like checking an account’s balance. If we no longer
need our variable, we can “close the account” by deleting the variable.
The key feature to note is that variables let us refer to data that either changes or is
calculated when a movie plays. Just as a bank account’s number remains the same
even though the account balance varies, a variable’s name remains fixed even though
the data it