ActionScript 2.0 is written like the JavaScript of its time, with a colon and a type after names that are given one. Its main lexical change from ActionScript 1.0 is that case now matters everywhere. The text is read in the encoding set in Flash’s preferences; see The .as file.
White space and semicolons
Spaces, tabs and line breaks separate words and are otherwise ignored, outside
strings. A semicolon ends a statement and may be left out at the end of a line, but
Macromedia’s guides and the class files that ship with Flash always write it.
return followed by a line break returns nothing. Blocks in braces need no
semicolon after them; a function literal assigned to a variable does. Member
declarations in a class end with a semicolon, method bodies do not.
Identifiers
Names are made of letters A to Z and a to
z, digits, _ and $, and may not start with a
digit or be a keyword. Class and interface names are written with a capital by
convention, and fully qualified names join package names and the class name with dots:
com.example.ui.Counter. Flash’s built-in properties keep their leading
underscore: _x, _root, _global.
Macromedia recommended suffixes for instance names, so that the Actions panel could
offer code hints without type annotations: _mc for movie clips,
_btn for buttons, _txt for text fields, _sound,
_xml, _lv for LoadVars and others. They are a convention, not
a rule.
Case sensitivity
Case matters in two separate places, and ActionScript 2.0 settles both:
| Where | Rule |
|---|---|
| The ActionScript 2.0 compiler | Always case-sensitive: myScore and myscore are different names, and movieclip is not a type. The ActionScript 1.0 compiler is not. |
| A SWF file for Flash Player 7 or later | Case-sensitive when it runs: variable, property and function names, instance names, frame labels and linkage names must match exactly. This holds for ActionScript 1.0 code in such a file too. |
| A SWF file for Flash Player 6 | Names are matched without regard to case when it runs, even though the compiler checked them. Keywords are case-sensitive in every version. |
So an ActionScript 2.0 class can compile but misbehave in a Flash Player 6 file if it relies on two names that differ only in case, and old code moved to a Flash Player 7 file can break where it spelt one name in several ways.
Keywords
These words are reserved and cannot be used as names. The Flash 4 words are deprecated but still reserved.
| Group | Words |
|---|---|
| Statements | break, case, catch, continue, default, do, else, finally, for, function, if, in, return, switch, throw, try, var, while, with |
| Classes and packages | class, dynamic, extends, implements, import, interface, intrinsic, private, public, static, super, get and set (before a method name) |
| Operators | delete, instanceof, new, typeof, void |
| Values | this, true, false, null; undefined, NaN, Infinity and newline are built-in constants |
| Handlers | on, onClipEvent |
| Flash 4 | add, and, eq, ge, gt, ifFrameLoaded, le, lt, ne, not, or, tellTarget |
These were set aside for later use and should not be used as names:
abstract, boolean, byte, char,
const, debugger, double, enum,
export, final, float, goto,
int, long, native, package,
protected, short, synchronized,
throws, transient and volatile. Several of them
became keywords of ActionScript 3.0. The names of the built-in classes, such as
Array and Date, are not keywords but should not be reused as
variable names.
Literals
| Kind | Examples | Notes |
|---|---|---|
| Number | 42, -7, 3.14, .5, 12e2 | Double-precision floating point; type Number. |
| Hexadecimal | 0xFF, 0x00CC66 | Common for colours. |
| String | "text", 'text' | Type String; escapes below. |
| Boolean | true, false | Type Boolean. |
| Empty values | null, undefined | Allowed for any type. |
| Special numbers | NaN, Infinity, -Infinity | |
| Array | [1, "two", [3]] | Type Array. |
| Object | {x: 10, y: 20} | Type Object. |
| Function | function (a:Number):Number { return a * 2; } | Type Function; parameters and result may be typed. |
Escape sequences in strings
| Escape | Character |
|---|---|
\b, \f, \n, \r, \t | Backspace, form feed, line feed, carriage return, tab |
\', \", \\ | Single quote, double quote, backslash |
\xNN | The character with a two-digit hexadecimal code |
\uNNNN | The Unicode character with a four-digit hexadecimal number |
Strings are Unicode, so any character can be written directly in a UTF-8 file or
with \u; it shows on screen if the font has it.
Comments
// text/* text *//** text */