USING IF STATEMENT TO TEST A CONDITION IN FLASH



The ActionScript if, else if, and else actions provide you the ability to have your script make similar decisions.

Think you need an ActionScript that requires the user to guess a number. If the user guesses the correct number, the script should send a message to the user that says, You are amazing! You can use the if action to create your script. The syntax for the if action is

if (condition){
statement;
}


The if action takes two arguments, a condition and a statement. The condition is an expression that evaluates to either true or false. The statement is the instruction to be executed if the condition is true. The if action evaluates the condition. If the condition is true, ActionScript performs the statement. If the condition is not true, ActionScript performs the next statement outside of its block of code, for example:

on (release) {
if (guess == "7") {
message = "You are amazing!";
}
}


The user makes an entry in the input text box called guess. ActionScript compares the value of guess with 7. If guess is equal to 7, ActionScript displays the message "You are amazing."

You can use the if statement anytime you want to execute a statement only if a specific condition is met. In the above example the script executes when guess is equal to 7. It could be set to execute when guess is greater than 7, less than 7, or some other condition.

Below steps shows you how to use the if statement in flash:

1) Select the frame, button, or movie clip to which you want to add ActionScript.

This example uses a button.

2) Open the Object Actions panel.

3) Click Actions.

4) Double-click if.

5) Type the condition ActionScript to evaluate.

6) Click Actions.

7) Double-click set variable.

8) Assign a value to the variable.

9) Write the query or command for returning to the users.

10) Move to the test environment.

11) Type a number.

12) Click the button to get a response.

13) ActionScript uses the if action to evaluate your entry and responds with a message if the value you enter is the value for which it is looking.



When you are working with if statements, the operators shown in this table are extremely helpful.

OPERATORS and USE

Code:
>		Less than
< 		Greater than
== 	Equal to
>= 	Greater than or equal to
<= 	Less than or equal to
!= 		Not equal