|
|
 |
| |
|
|
ActionScript control statements
Author:
Animator
Level :
Beginner
Environment :
Adobe Flash MX Professional 2004
|
|
|
|
|
| |
Actionscript control statements
Like any other programming language ActionScript also uses control statements to control the flow of execution.
if
The if statement allows us to control the flow of our program execution based on some conditions. The if statement is Action Script's conditional branching statement. It can be used to route the program execution in any of the two different program paths. The syntax for using the if statement is
if(condition)
{
// statements
}
The statements will be executed only if the conduit evaluates to true.
For eg:
if( a == 10)
{
b == a + 10;
}
If we want to perform a different action if the condition is false we have else statement. The syntax for else statement is
if (condition) {
//statements
}
else {
//statements
}
For eg:
if(a == 10)
{
b = a+10;
}
else
{
b = a + 20;
}
If the condition evaluates to true, the statement b= a+ 10; will be executed and if the condition evaluates to false the statement b = a+ 20 will be executed. But at any time only one statement will be executed.
By using the if statement we can check multiple conditions. The above constructs checks for only one conditions. If we want to test for multiple conditions we need to use elseif constructs. The syntax for else if is
if (condition 1) {
// statements 1
} else if (condition 2) {
// statements 2
}
else if(condition 3) {
// statements 3
}
else {
}
// statements 4
}
if the condition 1 evaluates to true then statements 1 will be executed and the rest all the conditions and the else part will be ignored. If the condition 1 evaluates to a value false, then the second condition will be executed. If the condition 2 evaluates to true then statements 2 will be executed and if it evaluates to false then ActionScript would check for condition 3. And if no conditions evaluates to a true value then statements in else block will be executed.
In an if else construct only the if part mandatory. The else and else if blocks are optional. We can give as many number of else if depending on our requirement. But we can have only one else part.
|
|
| |
|
|
|
 |
|