Adobe Logo

ActionScript 2.0 Language Reference

Constants

A constant is a variable used to represent a property whose value never changes. This section describes global constants that are available to every script.


Constants
       false
A unique Boolean value that represents the opposite of true.
       Infinity
Specifies the IEEE-754 value representing positive infinity.
       -Infinity
Specifies the IEEE-754 value representing negative infinity.
       NaN
A predefined variable with the IEEE-754 value for NaN (not a number).
       newline
Inserts a carriage return character (\r) that generates a blank line in text output generated by your code.
       null
A special value that can be assigned to variables or returned by a function if no data was provided.
       true
A unique Boolean value that represents the opposite of false.
       undefined
A special value, usually used to indicate that a variable has not yet been assigned a value.


Constant detail

false Constant

Player version:  Flash Player 5

A unique Boolean value that represents the opposite of true.

When automatic data typing converts false to a number, it becomes 0; when it converts false to a string, it becomes "false".

Example
This example shows how automatic data typing converts false to a number and to a string:
var bool1:Boolean = Boolean(false);

// converts it to the number 0
trace(1 + bool1); // outputs 1

// converts it to a string
trace("String: " + bool1); // outputs String: false


Infinity Constant

Player version:  Flash Player 5

Specifies the IEEE-754 value representing positive infinity. The value of this constant is the same as Number.POSITIVE_INFINITY.

See also
    Number.POSITIVE_INFINITY


-Infinity Constant

Player version:  Flash Player 5

Specifies the IEEE-754 value representing negative infinity. The value of this constant is the same as Number.NEGATIVE_INFINITY.

See also
    Number.NEGATIVE_INFINITY


NaN Constant

Player version:  Flash Player 5

A predefined variable with the IEEE-754 value for NaN (not a number). To determine whether a number is NaN, use isNaN().

See also
    isNaN(), Number.NaN


newline Constant

Player version:  Flash Player 4

Inserts a carriage return character (\r) that generates a blank line in text output generated by your code. Use newline to make space for information that is retrieved by a function or statement in your code.

Example
The following example shows how newline displays output from the trace() statement on multiple lines. The following example shows how newline writes output from the trace() statement on multiple lines.
var myName:String = "Lisa", myAge:Number = 30;
trace(myName+myAge);
trace("-----");
trace(myName+newline+myAge);
// output:
Lisa30
-----
Lisa
30

See also
    trace()


null Constant

Player version:  Flash Player 5

A special value that can be assigned to variables or returned by a function if no data was provided. You can use null to represent values that are missing or that do not have a defined data type.

Example
The following example checks the first six values of an indexed array and outputs a message if no value is set (if the value == null):
var testArray:Array = new Array();
testArray[0] = "fee";
testArray[1] = "fi";
testArray[4] = "foo";

for (i = 0; i < 6; i++) {
    if (testArray[i] == null) {
        trace("testArray[" + i + "] == null");
    }
}

The output is the following:

testArray[2] == null
testArray[3] == null
testArray[5] == null


true Constant

Player version:  Flash Player 5

A unique Boolean value that represents the opposite of false. When automatic data typing converts true to a number, it becomes 1; when it converts true to a string, it becomes "true".

Example
The following example shows the use of true in an if statement:
var shouldExecute:Boolean;
// ...
// code that sets shouldExecute to either true or false goes here
// shouldExecute is set to true for this example:

shouldExecute = true;

if (shouldExecute == true) {
    trace("your statements here");
}

// true is also implied, so the if statement could also be written:
// if (shouldExecute) {
//         trace("your statements here");
// }
The following example shows how automatic data typing converts true to the number 1:
var myNum:Number;
myNum = 1 + true;
trace(myNum); // output: 2

See also
    false constant, Boolean class


undefined Constant

Player version:  Flash Player 5

A special value, usually used to indicate that a variable has not yet been assigned a value. A reference to an undefined value returns the special value undefined. The ActionScript code typeof(undefined) returns the string "undefined". The only value of type undefined is undefined.

In files published for Flash Player 6 or earlier, the value of String(undefined) is "" (an empty string). In files published for Flash Player 7 or later, the value of String(undefined) is "undefined" (undefined is converted to a string).

In files published for Flash Player 6 or earlier, the value of Number(undefined) is 0. In files published for Flash Player 7 or later, the value of Number(undefined) is NaN.

The value of undefined.toString() is undefined.

The value undefined is similar to the special value null. When null and undefined are compared with the equality (==) operator, they compare as equal. However, when null and undefined are compared with the strict equality (===) operator, they compare as not equal.

Example

In the following example, the variable x has not been declared and therefore has the value undefined.

In the first section of code, the equality operator (==) compares the value of x to the value undefined, and the appropriate result is sent to the Output panel. In the first section of code, the equality operator (==) compares the value of x to the value undefined, and the appropriate result is sent to the log file.

In the second section of code, the equality (==) operator compares the values null and undefined.

// x has not been declared
trace("The value of x is "+x);

if (x == undefined) {
    trace("x is undefined");
} else {
    trace("x is not undefined");
}

trace("typeof (x) is "+typeof (x));

if (null == undefined) {
    trace("null and undefined are equal");
} else {
    trace("null and undefined are not equal");
}
The following result is displayed in the Output panel. The following result is written to the log file.
The value of x is undefined
x is undefined
typeof (x) is undefined
null and undefined are equal