82
Data and Data Types
Using strict data typing helps ensure that you don’t inadvertently assign an incorrect type of
value to a variable. Flash checks for typing mismatch errors at compile time, and displays an
error message if you use the wrong type of value. Therefore, using strict typing also helps to
ensure that you do not attempt to access properties or methods that are not part of an object’s
type. Strict data typing means the ActionScript editor automatically shows code hints
for objects.
For more information on creating variables, see
“About variables” on page 86
. For
information on naming variables, see
“About naming variables” on page 91
. For more
information on assigning data types, and the types you can assign, see
“Assigning a data type”
on page 82
.
You can find a sample source file, datatypes.fla, in the Samples folder on your hard disk,
which shows you how to use data types in an application.
■
In Windows, browse to
boot drive
\Program Files\Macromedia\Flash 8\Samples and
Tutorials\Samples\ActionScript\DataTypes.
■
On the Macintosh, browse to
Macintosh HD
/Applications/Macromedia Flash 8/Samples
and Tutorials/Samples/ActionScript/DataTypes.
Assigning a data type
You need to assign data types whenever you define a variable, whether you declare a variable
using the
var
keyword, create a function argument, set function return type, or define a
variable to use within a
for
or
for..in
loop. To assign a data type, you use
post-colon syntax
,
which means you follow the variable name with a colon and then the data type:
var my_mc:MovieClip;
There are many possibilities for data types, ranging from the native data types such as
Number, String, Boolean, or built-in classes that are included in Flash Player 8, such as
BitmapData, FileReference, or even custom classes that you or other developers have written.
The most common types of data types you might need to specify are the built-in data types
such as Number, String, Boolean, Array, or Object, which are shown in the following
code examples.
Содержание 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...