else statement

if (condition){ 
statement(s); 
} else { 
statement(s); 
}

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.

Availability: ActionScript 1.0; Flash Player 4

Parameters

condition:Boolean - An expression that evaluates to true or false.

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 statement


Flash CS3