About statements

A statement is an instruction you give the FLA file to do something, such as to perform a particular action. For example, you can use a conditional statement to determine whether something is true or exists. Then your code might execute actions that you specify, such as functions or expressions, based on whether the condition is true or not.

For example, the if statement is a conditional statement and evaluates a condition to determine the next action that should occur in your code.

// if statement
if (condition) {
    // statements;
}

Another example is the return statement, which returns a result as a value of the function in which it executes.

There are many different ways for you to format or write ActionScript. You might differ from someone else who writes ActionScript in the way you form syntax, such as the way you space out your statements or where you put curly braces ({}) in your code. Even though there are several different ways you can form statements without breaking your code, there are some general guidelines you can follow to write well-formed ActionScript.

Place only one statement on a line to increase the readability of your ActionScript. The following example shows the recommended and not recommended statement usage:

theNum++;       // recommended
theOtherNum++;  // recommended
aNum++; anOtherNum++;  // not recommended

Assign variables as separate statements. Consider the following ActionScript example:

var myNum:Number = (a = b + c) + d;

This ActionScript embeds an assignment within the code, which is difficult to read. If you assign variables as separate statements, it improves readability, as the following example shows:

var a:Number = b + c;
var myNum:Number = a + d;

The following sections show you how to form specific statements in ActionScript. For information on writing and formatting events, see Handling Events.

For more information on each statement, see the following topics:


Flash CS3


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00000699.html