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 summary
false constantA 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". Availability: ActionScript 1.0; Flash Player 5 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 constantSpecifies the IEEE-754 value representing positive infinity. The value of this constant is the same as Number.POSITIVE_INFINITY. Availability: ActionScript 1.0; Flash Player 5 See also POSITIVE_INFINITY (Number.POSITIVE_INFINITY property) -Infinity constantSpecifies the IEEE-754 value representing negative infinity. The value of this constant is the same as Number.NEGATIVE_INFINITY. Availability: ActionScript 1.0; Flash Player 5 See also NEGATIVE_INFINITY (Number.NEGATIVE_INFINITY property) NaN constantA predefined variable with the IEEE-754 value for NaN (not a number). To determine whether a number is NaN, use isNaN(). Availability: ActionScript 1.0; Flash Player 5 See also isNaN function, NaN (Number.NaN property) newline constantInserts 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. Availability: ActionScript 1.0; Flash Player 4 Example The following example shows how newline displays 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 function null constantA 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. Availability: ActionScript 1.0; Flash Player 5 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 constantA 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". Availability: ActionScript 1.0; Flash Player 5 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 undefined constantA 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 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. Availability: ActionScript 1.0; Flash Player 5 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 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 value of x is undefined x is undefined typeof (x) is undefined null and undefined are equal |