User Guide
56 ActionScript Language and Syntax
Many programming languages distinguish between primitive values and their wrapper
objects. Java, for example, has an int primitive and the java.lang.Integer class that wraps it.
Java primitives are not objects, but their wrappers are, which makes primitives useful for some
operations and wrapper objects better suited for other operations. In ActionScript 3.0,
primitive values and their wrapper objects are, for practical purposes, indistinguishable. All
values, even primitive values, are objects. Flash Player treats these primitive types as special
cases that behave like objects but that don’t require the normal overhead associated with
creating objects. This means that the following two lines of code are equivalent:
var someInt:int = 3;
var someInt:int = new int(3);
All the primitive and complex data types listed above are defined by the ActionScript 3.0 core
classes. The core classes allow you to create objects using literal values instead of using the
new
operator. For example, you can create an array using a literal value or the Array class
constructor, as follows:
var someArray:Array = [1, 2, 3]; // literal value
var someArray:Array = new Array(1,2,3); // Array constructor
Type checking
Type checking can occur at either compile time or run time. Statically typed languages, such
as C++ and Java, do type checking at compile time. Dynamically typed languages, such as
Smalltalk and Python, handle type checking at run time. As a dynamically typed language,
ActionScript 3.0 has run-time type checking, but also supports compile-time type checking
with a special compiler mode called strict mode. In strict mode, type checking occurs at both
compile time and run time, but in standard mode, type checking occurs only at run time.
Dynamically typed languages offer tremendous flexibility when you structure your code, but
at the cost of allowing type errors to manifest at run time. Statically typed languages report
type errors at compile time, but at the cost of requiring type information to be known at
compile time.
Compile-time type checking
Compile-time type checking is often favored in larger projects because as the size of a project
grows, data type flexibility usually becomes less important than catching type errors as early as
possible. This is why, by default, the ActionScript compiler in Adobe Flash CS3 and Adobe
Flex Builder 2 is set to run in strict mode. You can disable strict mode in Flex Builder 2
through the ActionScript compiler settings in the Project Properties dialog box.