Top Level

# Boolean - AS3

Package | Top Level
Class | public final class Boolean
Inheritance | Boolean Object

Language Version: | ActionScript 3.0

Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4

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:

Copy

    var flag:Boolean = true;
    var flag:Boolean = new Boolean(true);
    var flag:Boolean = Boolean(true);

View the examples

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | constructor : Object A reference to the class object or constructor function for a given object instance. | Object

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | Boolean(expression:Object = false) Creates a Boolean object with the specified value. | Boolean
|  | hasOwnProperty(name:String):Boolean Indicates whether an object has a specified property defined. | Object
|  | isPrototypeOf(theClass:Object):Boolean Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter. | Object
|  | propertyIsEnumerable(name:String):Boolean Indicates whether the specified property exists and is enumerable. | Object
|  | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void Sets the availability of a dynamic property for loop operations. | Object
|  | toLocaleString():String Returns the string representation of this object, formatted according to locale-specific conventions. | Object
|  | toString():String Returns the string representation ("true" or "false") of the Boolean object. | Boolean
|  | valueOf():Boolean Returns true if the value of the specified Boolean object is true; false otherwise. | Boolean

Constructor Detail

### Boolean

()
Constructor

`public function Boolean(expression:Object = false)`

Language Version: | ActionScript 3.0

Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4

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.

Related API Elements

Boolean() global function
Example ( How to use this example )
The following code creates a new Boolean object, initialized to a value of `false` called `myBoolean`:
Copy

     var myBoolean:Boolean = new Boolean();

Method Detail

### toString

()
method

`AS3 function toString():String`

Language Version: | ActionScript 3.0

Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4

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 ( How to use this example )
This example creates a variable of type Boolean and then uses the `toString()` method to convert the value to a string for use in an array of strings:
Copy

         var myStringArray:Array = new Array("yes", "could be");
         var myBool:Boolean = 0;
         myBool.toString();
         myStringArray.push(myBool);
         trace(myStringArray); // yes,could be,false

### valueOf

()
method

`AS3 function valueOf():Boolean`

Language Version: | ActionScript 3.0

Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4

Returns `true` if the value of the specified Boolean object is true; `false` otherwise.

Returns

| `Boolean` — A Boolean value.

Example ( How to use this example )
The following example shows how this method works, and also shows that the value of a new Boolean object is `false`:
Copy

         var myBool:Boolean = new Boolean();
         trace(myBool.valueOf());   // false
         myBool = (6==3+3);
         trace(myBool.valueOf());   // true

Examples How to use this example
BooleanExample.as
The following example toggles and displays each corresponding value for the Boolean object:
Copy

     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;
            }
        }
    }

© 2015 Adobe Systems Incorporated. All rights reserved.
Mon Apr 10 2017, 12:28 PM -07:00