6 Types

A type is a set of values. Expressions have known values at runtime, and properties have known types at compile time (as well as at runtime.) The various types of ActionScript 3.0 can be related graphically as a type lattice where the edges of the lattice indicate subset relationships.

The following diagram shows the relationships between the main built-in types of the language:



There are three fundamental program visible types (Null, Object and void). What makes these types fundamental is that their union includes all possible values in the language. Null includes null, void includes undefined, and Object includes every other value. Null and void are different because they do not have object-like properties (such as toString, valueOf), and they both have values that represent a missing value.

The type Null includes one value - the value that results of the primary expression null. The value null is used to represent the idea "no value" in the context of an Object typed reference.

The type void includes one value - the value that is the initial value of the global property undefined and the result of the unary expression void 0. The value undefined is used to represent the idea "no property" or "no value" in the context of an untyped reference.

While the need for two types that represent the idea of "no value" seems strange to programmers familiar with statically typed object-oriented languages, the distinction is useful in ActionScript 3.0 to represent the absence of a property or the absence of a value of an untyped property versus the absence of a typed property. Here is an example:

dynamic class A {
var x : String
var y
}
var a : A = new A
print(a.x)    // null
print(a.y)    // undefined
print(a.z)    // undefined
a.y = 10
a.z = 20
print(a.y)    // 10
print(a.z)    // 20

When dealing with dynamic instances, there is little difference between a property that doesn't exist and a property with no type and no value. But there is a difference between a property that has a type and one that doesn't. This is one of the reasons for the existence of both types Null and void.

NOTE

 

In ECMA-262 edition 3, program visible values were instances of one of six unrelated types (Undefined, Null, Boolean, Number, String and Object). Conversions were provided to translate a value from one type to another. ActionScript 3.0 provides the same conversions between the primitive types (void/Undefined, Null, Boolean, String, Number, int and uint).


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/specs/actionscript/3/as3_specification50.html