MACROMEDIA FLEX-FLEX ACTIONSCRIPT LANGUAGE Reference page 24

Actionscript language reference
Table of Contents

Advertisement

"Casting objects" on page 25
"Determining an item's data type" on page 26
Automatic data typing
If you do not explicitly define an item as holding either a number, a string, or another data type,
Flash Player will, at runtime, 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;
A later assignment might change the type of
the type of
to a string. Because
x
determine the type; to the compiler, the variable
typing" on page
ActionScript converts data types automatically when an expression requires it and the variables
aren't strictly typed.
For example, when you pass a value to the
the value to a string and sends it to the log file.
In expressions with operators, ActionScript converts data types as needed; in the following
example, when used with a string, the addition (
a string:
"Next in line, number " + 7
ActionScript converts the number 7 to the string
resulting in the following string:
"Next in line, number 7"
Strict data typing is recommended; for more information, see
Strict data typing
ActionScript lets you explicitly declare the object type of a variable when you create it, which is
called strict data typing. Strict data typing offers several benefits at compile time. 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). Although strict data typing is relevant only at
compile time, it can increase performance at runtime by making your scripts run faster.
To assign a specific data type to an item, specify its type using the
syntax, as shown in the following example:
// strict typing of variable or object
var x:Number = 7;
var birthday:Date = new Date();
// strict typing of parameters
24
Chapter 1: ActionScript Basics
was not declared using strict data typing, the compiler cannot
x
24.)
; for example, the statement
x
can have a value of any type. (See
x
statement,
trace()
trace()
operator expects the other operand to be
+)
and adds it to the end of the first string,
"7"
"Strict data typing" on page
x = "hello"
"Strict data
automatically converts
keyword and post-colon
var
changes
24.

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLEX-FLEX ACTIONSCRIPT LANGUAGE and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flex

Table of Contents