Flow Control in Flash with Actionscript. Use of programming loops and controls

When we talk about Flow Control in programming, we are talking about logical control of the programming process. What the computer will do next when running your application.

If you are somewhat familiar with Flash, you may do a lot of your flow control by using the timeline. gotoAndPlay("frameLabel"); type actions. That kind of control can be handy, especially in Flash, which is timeline based. However, to write robust, interactive programs, you need more than timeline control.

This is where programming statements and loops can come in handy. Let's take a look at several different types of Flow Control in Actionscript:

If Statement

An If-Then-Else statement acts like a branch in the flow control

The syntax is like this:


if (boolean expression) then {
        //do something
} else if (boolean expression) {
        //do this instead
} else {
        //do something else
}
 

the boolean expression may sound like a scary thing, but it's very simple. A boolean expression is simply something that is either true or false. The boolean expression can be as simple as a boolean variable, or it can be a complex expression. Here are some examples:


if (initialized) { }
if (x > 10) { }
if (this.getBytesLoaded() == this.getBytesTotal()) { }
 

The first example is checking a boolean variable named "initialized" which would have been set somewhere else in your code. (If it is undefined, it will evaluate to false).

The second example is checking to see if the variable "x" has a value greater than 10.

The third example is calling a couple of functions that get the loaded and total bytes of the movie clip that contains this code, and then comparing the result. If they are the same, the boolean expression evaluates to "true", otherwise it evaluates to "false".