User Guide
ActionScript coding standards 95
Following general formatting guidelines
Adding spacing (or white space) to your syntax is recommended because it makes your
ActionScript easier to read. The following formatting points are recommended to help promote
readability in your ActionScript.
The following example includes a space after a keyword that is followed by parentheses [()]:
do {
//something
} while (condition);
You do not have to put a space between a method name and a following parentheses, as the
following example shows:
function checkLogin() {
//statements;
}
checkLogin();
If you follow these guidelines, it is easier to distinguish between method calls and keywords.
In a list of arguments, such as in the following example, include a space after commas:
function addItems(item1:Number, item2:Number):Number {
return (item1+item2);
}
var sum:Number = addItems(1, 3);
Separate all operators and their operands by spaces, as the following ActionScript shows:
var sum:Number = 7 + 3;
An exception to this guideline is the dot (.) operator. Unary operators such as increment (++) and
decrement (--) do not have spaces.
Using scope
Scope is the area where the variable is known and can be used in a SWF file, such as on the
timeline, globally across an application, or locally within a function. There are three kinds of
variables: local, timeline, and global. For information on these variables and scope, see “Scoping
and declaring variables” on page 45. ActionScript 2.0 classes also support public, private, and
static variable scopes.
It is important to understand the difference between the
_global and _root scopes. The _root
scope is unique for each loaded SWF file. Use the
_global identifier to create global objects,
classes, or variables. The global scope applies to all Timelines and scopes within SWF files. Use
relative addressing rather than references to
_root timelines, because it makes code reusable and
portable. See the following sections for the recommended way of scoping variables. For more
information on scope, see “Event handler scope” on page 174 and “Scope of the this keyword”
on page 176. For information on using the
super prefix, see “Using the super prefix” on page 87.
For more information on scope, see the following sections:
• “Avoiding _root” on page 96
• “Using _lockroot” on page 96