Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 65

Programming actionscript 3.0
Table of Contents

Advertisement

Object data type
The Object data type is defined by the Object class. The Object class serves as the base class
for all class definitions in ActionScript. The ActionScript 3.0 version of the Object data type
differs from that of previous versions in three ways. First, the Object data type is no longer the
default data type assigned to variables with no type annotation. Second, the Object data type
no longer includes the value
instances. Third, in ActionScript 3.0, the default value for instances of the Object class is
.
null
In previous versions of ActionScript, a variable with no type annotation was automatically
assigned the Object data type. This is no longer true in ActionScript 3.0, which now includes
the idea of a truly untyped variable. Variables with no type annotation are now considered
untyped. If you prefer to make it clear to readers of your code that your intention is to leave a
variable untyped, you can use the new asterisk (
equivalent to omitting a type annotation. The following example shows two equivalent
statements, both of which declare an untyped variable
var x
var x:*
Only untyped variables can hold the value
to a variable that has a data type, Flash Player will convert the value
undefined
the default value of that data type. For instances of the Object data type, the default value is
, which means that Flash Player will convert the value
null
to assign
undefined
Type conversions
A type conversion is said to occur when a value is transformed into a value of a different data
type. Type conversions can be either implicit or explicit. Implicit conversion, which is also
called coercion, is sometimes performed by Flash Player at run time. For example, if the value
2 is assigned to a variable of the Boolean data type, Flash Player converts the value 2 to the
Boolean value
before assigning the value to the variable. Explicit conversion, which is
true
also called casting, occurs when your code instructs the compiler to treat a variable of one data
type as if it belongs to a different data type. When primitive values are involved, casting
actually converts values from one data type to another. To cast an object to a different type,
you wrap the object name in parentheses and precede it with the name of the new type. For
example, the following code takes a Boolean value and casts it to an integer:
var myBoolean:Boolean = true;
var myINT:int = int(myBoolean);
trace(myINT); // 1
, which used to be the default value of Object
undefined
to an Object instance.
) symbol for the type annotation, which is
*
:
x
. If you attempt to assign the value
undefined
undefined
to
undefined
to
if you attempt
null
Data types
65

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents