ActionScript 3.

0 in Flash

Conditional Loops Arrays

You will often have the 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 addressed by conditionals.

If Condition
The statement’s basic structure is the if

keyword, followed by parentheses in which the conditional test resides, and braces in which the code resides that is executed when the statement evaluates to true. var a:Number = 1; var b:String = "hello"; var c:Boolean = false; if (a == 1) { trace("option a"); }

If and else Condition
Additional power can be added to the if

statement by adding an unconditional alternative (true no matter what)—that is, an alternative set of code is executed no matter what the value being tested is, simply because the test did not pass if (a != 1) { trace("a does not equal 1"); } else { trace("a does equal 1"); }

Switch Conditionfeature that lets you The latter statement has a unique
control which if any instructions are executed—even when a test evaluates to false. switch (a) { case 1 : trace("one"); break; case 2 : trace("two"); break; default : trace("other"); break; }

It is quite common to execute many repetitive

instructions in your scripts. However, including them line by line, one copy after another, is inefficient and difficult to edit and maintain.  Wrapping repetitive tasks in an efficient structure is the role of loops.

For Loop
This loop executes its contents a finite

number of times. for (var i:Number = 0; i < 3; i++) { trace("hello"); }

For Loop
It is also possible to count down by reversing

the values in steps 1 and 2, and then decrementing the counter: for (var i:Number = 3; i > 0; i--) { trace( i ); }

While Loop
Instead of executing its contents a finite

number of times, it executes as long as something remains true var num:Number = 0; while (num < .5) { num = Math.random(); trace ( num ); }

Conditional Loops Arrays

Sign up to vote on this title
UsefulNot useful