ActionScript tutorial  
  Home Computer Graphics Tutorials Tutorials Web Design tutorials Forums Computer Graphics Community Interview Interview Articles Articles Making Making About About US Contact us
 
*Home / Tutorials / Adobe Flash / ActionScript control statements
     
Maya tutorials   Autodesk Maya
Photoshop tutorials   Adobe Photoshop
Illustrator tutorials   Adobe Illustrator
flash tutorials   Adobe Flash
3Ds max tutorials   Autodesk 3D's Max
Premiere tutorials   Adobe Premiere
Dreamweaver tutorials   Adobe Dreamweaver
*
 

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.
 
 
 
  Bookmark   Googlize this * Add to Yahoo * Add To_Delicious * Digg It * Scrutinize this * Spurl this * Furl * Socializer * Onlywire
     
  Discuss This   Add to Any * Add this * Blink It *
 
*

Home | Tutorials | Forums | Interviews | Articles | Making | About the Team | Terms and Conditions | Privacy Policy | Contact us
Copyright © 2006-2007 CGShelf.com. All Rights Reserved