User Guide
70 ActionScript Language and Syntax
Boolean variables get special treatment in strict mode in that you can assign values of any data
type to a Boolean variable without casting. Implicit coercion from all data types to the
Boolean data type occurs even in strict mode. In other words, unlike almost all other data
types, casting to Boolean is not necessary to avoid strict mode errors. The following examples
all compile in strict mode and behave as expected at run time:
var myObj:Object = new Object(); // instantiate
var bool:Boolean = myObj;
trace(bool); // true
bool = "random string";
trace(bool); // true
bool = new Array();
trace(bool); // true
bool = NaN;
trace(bool); // false
The following table summarizes the results of casting to the Boolean data type from other data
types:
Casting to String
Casting to the String data type from any of the numeric data types returns a string
representation of the number. Casting to the String data type from a Boolean value returns the
string
“true” if the value is true, and returns the string “false” if the value is false.
Casting to the String data type from an instance of the Object class returns the string
“null”
if the instance is
null. Otherwise, casting to the String type from the Object class returns the
string
“[object Object]”.
Casting to String from an instance of the Array class returns a string comprising a comma-
delimited list of all the array elements. For example, the following cast to the String data type
returns one string containing all three elements of the array:
var myArray:Array = ["primary", "secondary", "tertiary"];
trace(String(myArray)); // primary,secondary,tertiary
Data type or value Result of conversion to Boolean
String false if the value is null or the empty string (""); true otherwise.
null false
Number, int or uint false if the value is NaN or 0; true otherwise.
Object false if the instance is null; true otherwise.