ActionScript 2.0 Language Reference |
|
All Packages | All Classes | Language Elements | Index | Frames |
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 |
Player version: | Flash Player 5 |
true
.
When automatic data typing converts false
to a number, it becomes 0; when it converts false
to a string, it becomes "false"
.
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
Player version: | Flash Player 5 |
Number.POSITIVE_INFINITY
.
See also
Number.POSITIVE_INFINITY
Player version: | Flash Player 5 |
Number.NEGATIVE_INFINITY
.
See also
Number.NEGATIVE_INFINITY
Player version: | Flash Player 5 |
isNaN()
.
See also
isNaN(), Number.NaN
Player version: | Flash Player 4 |
\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.
Examplenewline
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()
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.
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
Player version: | Flash Player 5 |
false
.
When automatic data typing converts true
to a number, it becomes 1; when
it converts true
to a string, it becomes "true"
.
Exampletrue
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"); // }
true
to the number 1:
var myNum:Number; myNum = 1 + true; trace(myNum); // output: 2
See also
false constant, Boolean class
Player version: | Flash Player 5 |
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.
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 value of x is undefined x is undefined typeof (x) is undefined null and undefined are equal
All Packages | All Classes | Language Elements | Index | Frames |