0% found this document useful (0 votes)
50 views

Core Language Conditionals

Conditionals are used to make decisions in your scripts. Loops wrap repetitive instructions in an efficient structure. While loops execute their contents a finite Number of times.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Core Language Conditionals

Conditionals are used to make decisions in your scripts. Loops wrap repetitive instructions in an efficient structure. While loops execute their contents a finite Number of times.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 11

ActionScript 3.

0 in Flash
Topics
Conditional
Loops
Arrays
Conditionals
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 Condition
The latter statement has a unique feature that lets you
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;
}
Loop
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 );
}
Summary
Conditional
Loops
Arrays

You might also like