About language punctuators
125
For more information on the dot (
.
) operator and array access (
[]
) operators, see
“Using dot
and array access operators” on page 184
. For information on white space and code formatting,
see
“Formatting ActionScript syntax” on page 764
.
Semicolons and colons
ActionScript statements terminate with a semicolon (
;
) character, as demonstrated in the
following two lines of code:
var myNum:Number = 50;
myClip._alpha = myNum;
You can omit the semicolon character and the ActionScript compiler assumes that each line of
code represents a single statement. However, it is good scripting practice to use semicolons
because it makes your code more readable. When you click the Auto Format button in the
Actions panel or Script window, trailing semicolons are appended to the end of your
statements by default.
Another place you use semicolons is in
for
loops. You use the semicolon to separate
parameters, as shown in the following example. The example loops from 0 to 9 and then
displays each number in the Output panel:
var i:Number;
for (i = 0; i < 10; i++) {
trace(i); // 0,1,...,9
}
You use colons (:) in your code to assign data types to your variables. To assign a specific data
type to an item, specify its type using the
var
keyword and post-colon syntax, as shown in the
following example:
// strict typing of variable or object
var myNum:Number = 7;
var myDate:Date = new Date();
// strict typing of parameters
function welcome(firstName:String, myAge:Number) {
}
// strict typing of parameter and return value
function square(num:Number):Number {
var squared:Number = num * num;
return squared;
}
NO
TE
Using a semicolon to terminate a statement allows you to place more than one statement
on a single line, but doing so usually makes your code more difficult to read.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...