User Guide

68 ActionScript Language and Syntax
In ActionScript 3.0, the Number() function no longer supports octal, or base 8, numbers. If
you supply a string with a leading zero to the ActionScript 2.0
Number() function, the
number is interpreted as an octal number, and converted to its decimal equivalent. This is not
true with the
Number() function in ActionScript 3.0, which instead ignores the leading zero.
For example, the following code generates different output when compiled using different
versions of ActionScript:
trace(Number("044"));
// ActionScript 3.0 44
// ActionScript 2.0 36
Casting is not necessary when a value of one numeric type is assigned to a variable of a
different numeric type. Even in strict mode, the numeric types are implicitly converted to the
other numeric types. This means that in some cases, unexpected values may result when the
range of a type is exceeded. The following examples all compile in strict mode, though some
will generate unexpected values:
var sampleUINT:uint = -3; // Assign value of type int and Number.
trace(sampleUINT); // 4294967293
var sampleNum:Number = sampleUINT; // Assign value of type int and uint.
trace(sampleNum) // 4294967293
var sampleINT:int = uint.MAX_VALUE + 1; // Assign value of type Number.
trace(sampleINT); // 0
sampleINT = int.MAX_VALUE + 1; // Assign value of type uint and Number.
trace(sampleINT); // -2147483648
The following table summarizes the results of casting to the Number, int, or uint data type
from other data types.
Data type or value Result of conversion to Number, int or uint
Boolean If the value is true, 1; otherwise, 0.
Date The internal representation of the Date object, which is the number
of milliseconds since midnight January 1, 1970, universal time.
null
0
Object If the instance is
null and converted to Number, NaN; otherwise, 0.
String A number if Flash Player can convert the string to a number;
otherwise,
NaN if converted to Number or 0 if converted to int or uint.
undefined
If converted to Number, NaN; if converted to int or uint, 0.