
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
155
Chapter 7
CHAPTER 7
Conditionals
Most of the code examples we’ve seen so far have been very linear—each statement
is executed in turn, starting with the first and ending with the last. Linear code
always does the same thing. A conditional, in contrast, is a type of statement that per-
forms an action only when a specified condition is met. In linear code, the inter-
preter might execute statement A, then statement B, then statement C. With
conditional statements, we can tell the interpreter to execute statement A, then exe-
cute either statement B or statement C, depending on condition X.
We can use conditionals to create and control situations that have more than one
potential outcome. For example, suppose we want to create a password-protected
site. When users attempt to log in, either the password is correct and the user is
allowed to enter the site, or the password is wrong and the user sees an error mes-
sage. The two outcomes require two very different blocks of code in our movie’s
script. One block needs to send the Flash playhead to a frame containing the site’s
welcome screen, and the other block needs to send the playhead to a frame with an
error message. But only one of the blocks should be executed when the user attempts
to log in. A conditional statement allows us to