EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - About Variables

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
86 Data and Data Types
The following example shows how you can use the typeof operator to return the kind of
object that you trace:
// Create a new instance of LoadVars class.
var my_lv:LoadVars = new LoadVars();
/* typeof operator doesn't specify class, only specifies that my_lv is an
object */
var typeResult:String = typeof(my_lv);
trace(typeResult); // object
In this example, you create a new String variable named myName, and then convert it into a
Number data type:
var myName:String = new String("17");
trace(myName instanceof String); // true
var myNumber:Number = new Number(myName);
trace(myNumber instanceof Number); // true
For more information about these operators, see typeof operator and instanceof
operator
in the ActionScript 2.0 Language Reference. For more information on testing and
debugging, see Chapter 18, “Debugging Applications,” on page 711 For more information on
inheritance and interfaces, see Chapter 8, “Inheritance,” on page 301. For more information
on classes, see Chapter 7, “Classes,” on page 225.
About variables
A variable is a container that holds information. The following ActionScript shows what a
variable looks like in ActionScript:
var myVariable:Number = 10;
This variable holds a numerical value. The use of :Number in the previous code assigns the
type of value that variable holds, called data typing. For more information on data typing, see
About assigning data types and strict data typing” on page 81 and Assigning a data type”
on page 82.
The container (represented by the variable name) is always the same throughout your
ActionScript, but the contents (the value) can change. You can change the value of a variable
in a script as many times as you want. When you change the value of a variable while the SWF
file plays, you can record and save information about what the user has done, record values
that change as the SWF file plays, or evaluate whether a condition is
true or false. You
might need the variable to continually update while the SWF file plays, such as when a
players score changes in a Flash game. Variables are essential when you create and handle user
interaction in a SWF file.

Table of Contents

Related product manuals