Tip:
Highlight text to annotate it
X
In ActionScript 3.0, or just about any other programming language for that
matter, variables are an important building block to creating applications.
In this chapter we will discuss how to create variables in your code and how to
work with them in ActionScript 3.0. Before we start writing the code for variables,
I want you to understand what variables are. Variables are containers that
hold or represent data. Now let's think of this shopping cart over on the right
here on the screen as a variable. So at this point it's holding flour. A variable
is a container in the same way. For example, if you create an application
that's on the Web and it has a login system, the variable may be called user name
and the value of that variable would be whichever user is logged in. So variables
can hold different types of data and different data, different times.
So with the shopping cart analogy, at one point the shopping cart may hold
flour and at another point the shopping cart may hold chilies, just like on the
Web in an application the user name variable may hold my name at a certain time
and then your name at another time. All contained in the same user name variable.
Variables can also hold different types of data altogether. Some variables are
made to hold numbers and other variables are made to hold text values that are
called Strings. There are also variables that hold many different pieces of
data. Just like a shopping cart can hold a whole array of groceries, an array
variable can hold multiple types of data and multiple pieces of related data.
So to recap, variables are fundamental part of ActionScript 3.0 and they are
containers that hold or represent data.