Example
trace(Boolean(-1)); // output: true
trace(Boolean(0)); // output: false
trace(Boolean(1)); // output: true
trace(Boolean(true)); // output: true
trace(Boolean(false)); // output: false
trace(Boolean("true")); // output: true
trace(Boolean("false")); // output: true
trace(Boolean("Craiggers")); // output: true
trace(Boolean("")); // output: false
If files are published for Flash Player 6 and earlier, the results differ for three of the preceding
examples:
trace(Boolean("true")); // output: false
trace(Boolean("false")); // output: false
trace(Boolean("Craiggers")); // output: false
This example shows a significant difference between use of the
function and the
Boolean()
Boolean class. The
function creates a Boolean value, and the Boolean class creates
Boolean()
a Boolean object. Boolean values are compared by value, and Boolean objects are compared by
reference.
// Variables representing Boolean values are compared by value
var a:Boolean = Boolean("a"); // a is true
var b:Boolean = Boolean(1); // b is true
trace(a==b); // true
// Variables representing Boolean objects are compared by reference
var a:Boolean = new Boolean("a"); // a is true
var b:Boolean = new Boolean(1); // b is true
trace(a == b); // false
See also
Boolean
call function
call(frame)
Deprecated since Flash Player 5. This action was deprecated in favor of the
function
statement.
40
ActionScript language elements