About writing conditions

Statements that check whether a condition is true or false begin with the term if. If the condition evaluates to true, ActionScript executes the next statement. If the condition evaluates to false, ActionScript skips to the next statement outside the block of code.

TIP

To optimize your code's performance, check for the most likely conditions first.

The following statements test three conditions. The term else if specifies alternative tests to perform if previous conditions are false.

if ((passwordTxt.text.length == 0) || (emailTxt.text.length == 0)) {
  gotoAndStop("invalidLogin");
}  else if (passwordTxt.text == userID){
  gotoAndPlay("startProgram");
}

In this code snippet, if the length of the passwordTxt or emailTxt text fields is 0 (for example, the user hasn't entered a value), the Flash document redirects to the invalidLogin frame label. If both the passwordTxt and emailTxt text fields contain values and the passwordTxt text field's contents match the userID variable, the SWF file redirects to the startProgram frame label.

If you want to check for one of several conditions, you can use the switch statement rather than multiple else if statements. For more information on switch statements, see Using a switch statement.

Refer to the following sections to learn how to write different kinds of conditions in your ActionScript applications.