About syntax, statements, and expressions

The ActionScript language is made up of the built-in classes that make up the ActionScript language. You need to use correct ActionScript syntax to form statements so the code compiles and runs correctly in Flash. In this case, syntax refers to the grammar and spelling of a language that you program with. The compiler cannot understand incorrect syntax, so you see errors or warnings displayed in the Output panel when you try to test the document in the test environment. Therefore, syntax is a collection of rules and guidelines that help you form correct ActionScript.

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 you might execute actions that you specify, such as functions or expressions, based on whether the condition is true or not. 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;
}

For more information on statements, see About statements.

Expressions, different from statements, are any legal combination of ActionScript symbols that represent a value. Expressions have values, while values and properties have types. An expression can consist of operators and operands, values, functions, and procedures. The expression follows ActionScript rules of precedence and of association. Typically, Flash Player interprets the expression and then returns a value that you can use in your application.

For example, the following code is an expression:

x + 2

In the previous expression, x and 2 are operands and + is an operator. For more information on operators and operands, see About operators. For more information on objects and properties, see Object data type.

The way you format your ActionScript also determines how maintainable your code is. For example, it's difficult to read the logic of a FLA file that doesn't contain indents or comments, or contains inconsistent formatting and naming conventions. When you indent blocks of ActionScript (such as loops and if statements), the code is easier to read and debug if you encounter problems. For more information about formatting ActionScript, see Formatting ActionScript syntax. You can also see proper formatting of ActionScript in these sections.

For more information on syntax and language fundamentals, 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/00000675.html