
Chapter 15
440
The Mystery of the If Statement
Often when you create Flash content, you
want one thing to happen under certain
conditions, and something else to happen
if those conditions aren’t met. Your script
needs to take di erent paths depending on
the state of a airs.
One way to accomplish this is by using the
if
statement, which takes this format:
if( condition )
{
action();
}
Here’s a real-world example:
if( numLives == 0 )
{
gotoAndStop( “gameOver” );
}
An
if
statement consists of the keyword
if
, followed by an opening parenthesis,
then a condition that is either true or false,
a closing parenthesis, and then a list of
statements between ...