User Guide

Syntax 31
Semicolons
An ActionScript statement is terminated with a semicolon (
;), as shown in the following
examples:
var column:Number = passedDate.getDay();
var row:Number = 0;
If you omit the terminating semicolon, Flash still compiles your script successfully. However, it is
good scripting practice to use semicolons because it makes your code more readable.
Semicolons are required within
for loops, as shown in the following example:
//For loop that adds numbers 1-10
var sum:Number = 0;
for (var i=1; i<=10; i++) {
sum += i;
}
Parentheses
When you define a function, place any parameters inside parentheses [()]:
function myFunction (name:String, age:Number, reader:Boolean){
// your code here
}
When you call a function, include any parameters passed to the function in parentheses, as
shown in the following example:
myFunction ("Steve", 10, true);
You can also use parentheses to override the ActionScript order of precedence or to make your
ActionScript statements easier to read. (See “Operator precedence and associativity” on page 49.)
You also use parentheses to evaluate an expression on the left side of a dot (.) in dot syntax. For
example, in the following statement, the parentheses cause
new Color(this) to evaluate and
create a Color object:
(new Color(this)).setRGB(0xffffff);
If you dont use parentheses, you must add a statement to evaluate the expression, as shown in the
following example:
myColor = new Color(this);
myColor.setRGB(0xffffff);
You can check for matching parentheses in your scripts; see “Checking syntax and punctuation
on page 150. For recommended guidelines on formatting and parentheses, see Chapter 3,
“Writing syntax and statements,” on page 89.
Comments
Using comments to add notes to scripts is highly recommended. Comments are useful for
tracking what you intended and for passing information to other developers if you work in a
collaborative environment or are providing samples. Even a simple script is easier to understand if
you make notes as you create it.