An ActionScript 3.0 file is a sequence of tokens: identifiers, keywords, literals, operators and punctuation, separated by white space, line breaks and comments. This page lists them all.
Basics
- Case – the language is case-sensitive:
num1andNum1are two different names, andVaris not the keywordvar. - Identifiers – a name starts with a letter,
_or$, followed by letters, digits,_or$. Letters outside ASCII are allowed. A keyword cannot be used as a name. - Semicolons – a semicolon ends a statement. It is optional at the end of a line: without one, the compiler takes the line as one statement. Several statements can share a line when semicolons separate them.
- Dot syntax –
.reaches properties and methods (sprite.x,sprite.addChild(c)) and separates the parts of a package name (flash.display.Sprite). - No slash syntax – the
/path/to:variablenotation of Flash 4 and the older versions is not supported. - White space – spaces, tabs and line breaks separate tokens and are otherwise ignored, except inside string, regular expression and XML literals.
Keywords and reserved words
Adobe’s documentation sorts the reserved words into three lists. Its lists name
native among both the keywords and the syntactic keywords, and
to among both the keywords and the future reserved words; they are given
here as Adobe gives them.
Keywords
These can never be used as names; the compiler reports an error.
as | break | case | catch | class | const |
continue | default | delete | do | else | extends |
false | finally | for | function | if | implements |
import | in | instanceof | interface | internal | is |
native | new | null | package | private | protected |
public | return | super | switch | this | throw |
to | true | try | typeof | use | var |
void | while | with |
Syntactic keywords
These can be used as names, but mean something special in particular places.
| Word | Where it is special |
|---|---|
each | After for, in for each (… in …). |
get | After function, declaring a getter. |
set | After function, declaring a setter. |
namespace | Declaring a namespace, and in use namespace and default xml namespace. |
include | As a directive followed by a string: include "file.as". |
dynamic | As a class attribute. |
final | As a class or method attribute. |
native | As a method attribute, for methods the runtime implements; not allowed in ordinary code. |
override | As a method attribute. |
static | As a class member attribute. |
Future reserved words
ActionScript 3.0 does not reserve these, but Adobe advises against them as names
because a later version might. ActionScript Compiler 2.0, in the AIR SDK, does
reject goto.
abstract | boolean | byte | cast | char | debugger |
double | enum | export | float | goto | intrinsic |
long | prototype | short | synchronized | throws | to |
transient | type | virtual | volatile |
Literals
A literal is a value written directly in the code.
| Kind | Examples | Notes |
|---|---|---|
| Number | 42, -7, 3.14, .5, 1e6, 2.5E-3 | Decimal; whole values fit int or uint where the type allows. |
| Hexadecimal | 0xFF, 0x00CC33 | Common for colours: 0xRRGGBB, or 0xAARRGGBB with alpha. |
| String | "text", 'text' | Either quote; escapes below. |
| Boolean | true, false | |
| Null | null | No object. |
| Undefined | undefined | A global constant rather than a keyword; only untyped (*) variables hold it. |
| Array | [1, 2, 3], [], ["a", [1, 2]] | The same as new Array(1, 2, 3). |
| Object | {x: 1, y: 2}, {"full name": "Ann"} | A plain Object with those properties. |
| Vector | new <int>[1, 2, 3] | A Vector.<int>; needs Flash Player 10 or AIR 1.5. |
| Regular expression | /ab+c/gi | Between slashes, then flags. See Regular expressions. |
| XML | <item id="1">Pen</item> | An XML object, written as XML in the code. See XML and E4X. |
| XMLList | <><a/><b/></> | An XMLList of the elements between <> and </>. |
| Function | function (a:int):int { return a * 2; } | A function expression; see Functions. |
String escape sequences
| Escape | Character |
|---|---|
\b | Backspace (U+0008) |
\f | Form feed (U+000C) |
\n | Line feed (U+000A) |
\r | Carriage return (U+000D) |
\t | Tab (U+0009) |
\" | Double quote |
\' | Single quote |
\\ | Backslash |
\unnnn | The UTF-16 code unit with four hexadecimal digits nnnn |
\xnn | The character with two hexadecimal digits nn |
Punctuation
| Token | Use |
|---|---|
{ } | Blocks, package, class and function bodies, object literals, and expressions inside XML literals. |
( ) | Grouping, calls, parameter lists, conditions, and E4X filters. |
[ ] | Array literals, indexing, and metadata tags such as [Embed(…)]. |
: | Type annotations (var n:int), object literal keys, labels and case labels. |
:: | Namespace qualification: flash_proxy::callProperty, CONFIG::debug. |
.< | Opens a type parameter: Vector.<String>. |
... | A rest parameter: function f(...args). |
; and , | End a statement; separate list items, or the comma operator. |
Operators are listed on the Operators page.
Comments
// text/* text */*/ends it./** text */ASDoc comments
An ASDoc comment goes directly before the declaration it describes: a class, interface, property, method, constant or an
[Event],[Style]or[Effect]metadata tag. Each line usually starts with*and a space, which ASDoc removes. The main description comes first; its first sentence, ending at the first full stop followed by a space or line break, is the summary. HTML is allowed but must be well formed, so<is written<and@in text@. Tags start at the first line that begins with@.@param name text@return text@throws Class text@see reference [text]@default value@eventType constant[Event]tag, the constant that names the event.@example text<listing>tags.@includeExample file@exampleText text@inheritDoc@copy reference@private@internal text@since text