About data types
81
If your application has multiple frames, the code does not execute a second time because the
init
variable is no longer undefined.
Void data type
The Void data type has one value,
void
, and is used in a function definition to indicate that
the function does not return a value, as shown in the following example:
//Creates a function with a return type Void
function displayFromURL(url:String):Void {}
About assigning data types and strict data typing
You use variables in Flash to hold values in your code. You can explicitly declare the object
type of a variable when you create the variable, which is called
strict data typing
.
If you do not explicitly define an item as holding either a number, a string, or another data
type, at runtime Flash Player will try to determine the data type of an item when it is assigned.
If you assign a value to a variable, as shown in the following example, Flash Player evaluates at
runtime the element on the right side of the operator and determines that it is of the Number
data type:
var x = 3;
Because
x
was not declared using strict data typing, the compiler cannot determine the type;
to the compiler, the variable
x
can have a value of any type. (See
“Assigning a data type”
on page 82
.) A later assignment might change the type of
x
; for example, the statement
x = "hello"
changes the type of
x
to String.
ActionScript always converts primitive data types (such as Boolean, Number, String, null, or
undefined) automatically when an expression requires the conversion and the variables aren’t
strictly typed.
Strict data typing offers several benefits at compile time. Declaring data types (strict data
typing) can help prevent or diagnose errors in your code at compile time. To declare a variable
using strict data typing, use the following format:
var variableName:datatype;
Because data type mismatches trigger compiler errors, strict data typing helps you find bugs in
your code at compile time and prevents you from assigning the wrong type of data to an
existing variable. During authoring, strict data typing activates code hinting in the
ActionScript editor (but you should still use instance name suffixes for visual elements).
NO
T
E
Strict data typing is sometimes called
strong typing
a variable.
Содержание 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...