You can test for more than one condition using the if..else if conditional statement.
For example, the following code not only tests whether the value
of x exceeds 20, but also tests whether the value
of x is negative:
if (x > 20)
{
trace("x is > 20");
}
else if (x < 0)
{
trace("x is negative");
}
If an if or else statement
is followed by only one statement, the statement does not need to
be enclosed in curly brackets. For example, the following code does
not use curly brackets:
if (x > 0)
trace("x is positive");
else if (x < 0)
trace("x is negative");
else
trace("x is 0");
However, Adobe recommends that you always use curly brackets,
because unexpected behavior can occur if statements are later added
to a conditional statement that lacks curly brackets. For example,
in the following code the value of positiveNums increases
by 1 whether or not the condition evaluates to true:
var x:int;
var positiveNums:int = 0;
if (x > 0)
trace("x is positive");
positiveNums++;
trace(positiveNums); // 1