Typing - Adobe FLEX 2-MIGRATING APPLICATIONS TO FLEX 2 Manual

Migrating applications to flex 2
Table of Contents

Advertisement

If you previously checked against undefined for a Number, you use a similar syntax; for
example:
if (n == undefined) // ActionScript 2.0
if (isNaN(n))

Typing

ActionScript 3.0 is more strongly typed than previous versions of ActionScript. This section
describes changes to the rules of typing.
Explicit typing
Flex 2 checks for type correctness for class and package property/methods at compile-time,
and enforces types at run time. By using stricter typing, you increase performance of your
application and strengthen the compile-time error checking.
If a variable is untyped, it will be treated as if it is type Object, which is slower than a Number,
int, uint, String, or Boolean. You should use Object only when absolutely necessary, and you
should never leave a variable untyped.
Use the most restrictive type that will work. Do not use Number if you can use int, and do
not use int if you can use uint. Use Class if something is a class reference.
In many cases, you will need to cast a general type to something more specific to get the
benefits of strong typing. Omitting types causes the Flex compiler to throw a warning, so your
applications will compile without this step.
The compiler enforces type checking wherever possible, but due to the dynamic nature of the
language, it does not checking style variable access or variables and functions declared outside
of classes (because they could be redefined dynamically at run time).
In ActionScript 3.0, type checking is performed at run time. In previous versions of
ActionScript, it was only checked at compile time. The following example shows how the
compiler will react
class a {
var b:String;
}
var c = new a();
c.b = 22;
// Results in a compiler error.
c["b"] = 22; // ActionScript 2.0 would allow this, but ActionScript 3.0
// throws a TypeError exception.
The arguments assigned to method parameters must have compatible number and types.
32
ActionScript 2.0 to 3.0
// ActionScript 3.0

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex 2

Table of Contents