| Language version: | ActionScript 3.0
|
A Boolean object is a data type that can have one of two values, either
true or
false,
used for logical operations. Use the Boolean
class to retrieve the primitive data type or string representation of a Boolean object.
To create a Boolean object, you can use the constructor or the global function, or assign a literal value.
It doesn't matter which technique you use; in ActionScript 3.0, all three techniques are equivalent. (This is
different from JavaScript, where a Boolean object is distinct from the Boolean primitive type.)
The following lines of code are equivalent:
var flag:Boolean = true;
var flag:Boolean = new Boolean(true);
var flag:Boolean = Boolean(true);
View the examples.
public function Boolean(expression:Object = false)
| Language version: | ActionScript 3.0
|
Creates a Boolean object with the specified value. If you omit the expression
parameter, the Boolean object is initialized with a value of false. If you
specify a value for the expression parameter, the method evaluates it and returns the result
as a Boolean value according to the rules in the global Boolean() function.
Parameters
| expression:Object (default = false) — Any expression.
|
See also
Example
AS3 function toString():String
| Language version: | ActionScript 3.0
|
Returns the string representation ("true" or
"false") of the Boolean object. The output is not localized, and is "true" or
"false" regardless of the system language.
Returns
| String —
The string "true" or "false".
|
Example
AS3 function valueOf():Boolean
| Language version: | ActionScript 3.0
|
Returns true if the value of the specified Boolean
object is true; false otherwise.
Returns
Example
The following example toggles and displays each corresponding value for the Boolean object:
package {
import flash.display.Sprite;
public class BooleanExample extends Sprite {
private var flag:Boolean;
public function BooleanExample() {
trace(flag); // false
toggle();
trace(flag); // true
toggle();
trace(flag); // false
}
private function toggle():void{
flag = !flag;
}
}
}
© 2004-2022 Adobe Systems Incorporated. All rights reserved.
Wed Sep 28 2022, 6:12 PM GMT+01:00