EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 89

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...
About variables 89
This example assigns the value of Pirate Eye to the catName variable. When you declare the
variable, you can also assign a value to it instead of assigning it afterwards (as in the previous
examples). You could set the
catName variable when you declare it, as shown in the
following example:
var catName:String = "Pirate Eye";
If you want to display the value of the catName variable in the test environment, you can use
the
trace() statement. This statement sends the value to the Output panel. You can trace the
value of the
catName variable and see that the actual value doesnt include the quotation
marks by using the following ActionScript:
var catName:String = "Pirate Eye";
trace(catName); // Pirate Eye
Remember that the value you assign must match the data type that you assign to it (in this
case, String). If you later try to assign a number to the
catName variable, such as catName =
10
, you will see the following error in the Output panel when you test the SWF file:
Type mismatch in assignment statement: found Number where String is
required.
This error tells you that you attempted to set the wrong data type to a specified variable.
When you assign a numeric value to a variable, the quotation marks arent necessary, as shown
in the following code:
var numWrinkles:Number = 55;
If you want to change the value of numWrinkles later in your code, you can assign a new
value using the following ActionScript:
numWrinkles = 60;
When you reassign a value to an existing variable, you dont need to use the var keyword or
define the variables data type (in this case,
:Number).
If the value is numeric or Boolean (
true or false), the value doesnt use straight quotes
(quotation marks). Examples of numeric and Boolean values are shown in the
following snippet:
var age:Number = 38;
var married:Boolean = true;
var hasChildren:Boolean = false;
In the previous example, the variable age contains an integer (nondecimal) value, although
you could also use a decimal or floating-point value such as 38.4. Boolean variables (such as
married or hasChildren) have only two possible values, true or false.

Table of Contents

Related product manuals