88
Data and Data Types
About declaring variables
You can declare variables on a frame in the timeline, directly on an object, or within an
external class file.
Define variables using the
var
keyword and follow the variable naming conventions. You can
declare a variable called
firstName,
as shown in the following example:
var firstName:String;
When you declare a variable, you assign a data type to the variable. In this case, you assign the
String data type to the
firstName
variable. For more information on assigning data types, see
“About assigning data types and strict data typing” on page 81
.
About default values
A
default value
is the value that a variable contains before you set its value. You
initialize
a
variable when you set its value for the first time. If you declare a variable, but do not set its
value, that variable is
uninitialized
. The value of an uninitialized variable defaults to the value
undefined
. For more information on creating and using variables, see
“About variables”
on page 86
.
About assigning values
You can define a
value
as the current contents of a variable. The value can be a strings,
numbers, arrays, objects, XML, dates, or even custom classes that you create. Remember, you
declare a variable in Flash using the
var
keyword. When you declare the variable, you also
assign a data type to the variable. You can also assign a value to a variable, as long as the value
matches the data type you assign to the variable.
The following example shows how you might create a variable called
catName:
var catName:String;
After you declare the variable, you can assign a value to it. You might follow the previous line
of ActionScript with this line:
catName = "Pirate Eye";
NO
TE
Because
Pirate Eye
is a string, the value needs to be enclosed in straight quotes
(quotation marks).
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...