ActionScript 1.0 is written much like JavaScript of the same time, with a few rules of its own kept for Flash 4 movies: names are not case-sensitive, and some words are reserved as operators. The text is read in the encoding described on The .as file.
White space and semicolons
Spaces, tabs and line breaks separate words and are otherwise ignored, except inside strings. A semicolon ends a statement. It may be left out at the end of a line, where the compiler takes the line break as the end, but the guides of the time advised always writing it. Some rules follow from this:
returnfollowed by a line break returnsundefined; the value must start on the same line.- A block in braces, as after
if,fororfunction name(), needs no semicolon after its closing brace. - An assignment of a function literal,
f = function () { … };, is a statement and ends with a semicolon. - Compiler directives such as
#includestand on a line of their own and take no semicolon.
Identifiers
Names of variables, functions, properties and objects are made of letters
A to Z and a to z, digits,
_ and $, and may not start with a digit. A name may not be a
reserved word. There is no set length limit.
Flash’s own properties start with an underscore: _x,
_alpha, _root, _parent. Names that need other
characters, or are built while the movie runs, can still be used as property names
with square brackets, this["item" + i], or with
eval and
set. Instance names of movie clips, frame labels and layer names
follow no rules of their own, but only those that are valid identifiers can be written
in dot syntax.
Case sensitivity
ActionScript 1.0 differs from ECMA-262 here, to keep Flash 4 movies working:
- Keywords are case-sensitive.
onClipEvent,functionandifmust be written exactly so;OnClipEventorIfis an error. - Everything else is not. Variable, property and function names,
built-in class names, instance names, frame labels and symbol linkage names are
matched without regard to case when the movie runs in a SWF file for Flash Player 6 or
earlier, which is everything Flash 5 and Flash MX make.
myScore,MyScoreandmyscoreare one variable, andnew array()makes an Array. - A consequence is that a variable can hide a class: after
date = new Date(), the nameDateon that timeline means the variable, not the constructor. Names such asmyDateavoid it.
The ActionScript 1.0 compiler does not check case either. The same code published as a SWF for Flash Player 7, which Flash MX 2004 can do, becomes case-sensitive when it runs, so old code with mixed spellings of one name breaks there.
Reserved words
These words are keywords in Flash 5 and cannot be used as names. The ones marked Flash 4 are the old operators and actions, kept but deprecated.
| Word | Use | Word | Use |
|---|---|---|---|
add | Flash 4 string join | le | Flash 4 string comparison |
and | Flash 4 logical and | lt | Flash 4 string comparison |
break | statement | ne | Flash 4 string comparison |
continue | statement | new | operator |
delete | operator | not | Flash 4 logical not |
do | statement | on | button handler |
else | statement | onClipEvent | clip handler |
eq | Flash 4 string comparison | or | Flash 4 logical or |
for | statement | return | statement |
function | statement and operator | tellTarget | Flash 4 action |
ge | Flash 4 string comparison | this | current object |
gt | Flash 4 string comparison | typeof | operator |
if | statement | var | statement |
ifFrameLoaded | Flash 4 action | void | operator |
in | for..in | while | statement |
with | statement |
Flash MX adds switch, case, default,
instanceof and super. The values true,
false, null, undefined, NaN,
Infinity and newline are built-in constants.
These words were set aside for the future and should not be used as names:
abstract, boolean,
byte, catch, char, class,
const, debugger, double, enum,
export, extends, final,
finally, float, goto,
implements, import, int,
interface, long, native,
package, private, protected,
public, short, static,
synchronized, throws, transient,
try and volatile. Several became keywords of ActionScript
2.0.
Literals
| Kind | Examples | Notes |
|---|---|---|
| Decimal number | 42, -7, 3.14, .5 | All numbers are double-precision floating point, about 15 significant digits. |
| Exponent | 12e2, 143E-3 | 1200 and 0.143. |
| Hexadecimal | 0xFF, 0X00CC66 | Much used for colours. |
| Octal | 0723 | A leading zero means octal: 0723 is 467. |
| String | "text", 'text' | Single or double quotes, matched; escapes below. |
| Boolean | true, false | |
| Empty values | null, undefined | See Data types. |
| Special numbers | NaN, Infinity, -Infinity | |
| Array | [1, "two", [3]] | Makes a new Array. |
| Object | {x: 10, y: 20, name: "ball"} | Makes a new Object with those properties. |
| Function | function (a, b) { return a + b; } | An anonymous function; see Functions. |
Escape sequences in strings
| Escape | Character |
|---|---|
\b | Backspace (8) |
\f | Form feed (12) |
\n | Line feed (10), a line break |
\r | Carriage return (13), a line break |
\t | Tab (9) |
\' | Single quote |
\" | Double quote |
\\ | Backslash |
\xNN | The character with this two-digit hexadecimal code, such as \xA9 for © |
\uNNNN | The character with this four-digit hexadecimal Unicode number, such as © |
In Flash 5 the \u form only gives the right character when it is in
Latin-1 or Shift-JIS, because Flash Player 5 has no Unicode. From Flash MX it reaches
any character, given a font that has it.
Comments
// text/* text */*/ends it.//!-- UTF8