User Guide
286 Chapter 2: ActionScript Language Reference
else
Availability
Flash Player 4.
Usage
if (condition){
statement(s);
} else {
statement(s);
}
Parameters
condition
An expression that evaluates to true or false.
statement(s) An alternative series of statements to run if the condition specified in the if
statement is
false.
Returns
Nothing.
Description
Statement; specifies the statements to run if the condition in the if statement returns false. The
curly braces (
{}) used to enclose the block of statements to be executed by the else statement are
not necessary if only one statement will execute.
Example
In the following example, the else condition is used to check whether the age_txt variable is
greater than or less than 18:
if (age_txt.text>=18) {
trace("welcome, user");
} else {
trace("sorry, junior");
userObject.minor = true;
userObject.accessAllowed = false;
}
In the following example, curly braces ({}) are not necessary because only one statement follows
the
else statement:
if (age_txt.text>18) {
trace("welcome, user");
}
else trace("sorry, junior");
See also
if, else if, switch
CHAPTER 2
ActionScript Language Reference