Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Conditionals

You will often need to make a decision in your script, choosing to do one thing under one circumstance and another thing under a different circumstance. These situations are usually handled by conditionals. Put simply, a test asks whether a condition is met. If the condition is met, the test evaluates to true and specific code is executed accordingly. If the condition is not met, either no further action is taken or an alternate set of code is executed. We’ll now take a look at the if and switch conditional structures.

You can try this code for yourself, or look at the conditionals.fla source file from the chapter archive found in the Downloads section of the companion website. This section provides multiple examples of conditionals to teach the logic behind their use. For an additional practical example, revisit the opening of this chapter, which uses a conditional to perform one of two tasks based on a random number value.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint