ActionScript 2.0 needs no new virtual machine. The compiler checks the classes and types, then writes the same kind of AVM1 bytecode as for ActionScript 1.0, building each class out of a constructor function and a prototype. The result runs in Flash Player 6 and later, best in 7 and later.
Compilers
| Compiler | Notes |
|---|---|
| Flash MX 2004, Flash 8, Flash CS3 to CS6 | Built into the authoring program; compiles when the movie is published or tested, or when syntax is checked. |
| MTASC | Motion-Twin’s free command-line compiler, written in OCaml, from 2004. Much faster than Flash’s and stricter about types. It compiles classes into an existing SWF file or a new one, and was used with FlashDevelop and build scripts. |
| Flex 1.0 and 1.5 | Macromedia’s server product compiled MXML and ActionScript 2.0 into SWF files for Flash Player 7 when a page was requested. |
Publish settings
| Setting | Effect |
|---|---|
| ActionScript version | 1.0 or 2.0. With 2.0, class files are found and compiled, annotations are checked and the compiler is case-sensitive. |
| Version | The Flash Player to publish for: 6 or later for ActionScript 2.0. It sets the SWF version, which bytecode actions may be used, and which conversion and case rules the player applies. |
| Settings: export frame for classes | The frame in which compiled classes are placed, 1 by default. |
| Settings: classpath | The document classpath, searched before the global one. |
| Omit trace actions | Leaves trace calls out. |
| Protect from import, Permit debugging | Mark the SWF, with optional passwords. |
| Compress movie | Compresses the SWF file with zlib. |
| Local playback security | Flash 8: whether a local SWF may read local files or the network. |
Compile errors
Flash reports errors in the Output panel, from Flash CS3 in a Compiler Errors panel,
with the file or the scene, layer and frame, and the line. The ActionScript 2.0
compiler numbers its errors from the first version, Flash MX 2004: Appendix A,
“Error Messages”, of Macromedia’s Using ActionScript in Flash for
Flash MX 2004 lists 1093 to 1201, with no 1098. Flash 8’s Learning ActionScript
2.0 in Flash repeats that list, in places reworded (1142 “The class or
interface … could not be loaded”, 1150 and 1151 “export your Flash movie”), and adds
1202 to 1213, with no 1209. A pair of quotes '' is where the compiler puts a name,
which the manuals write as ‘<ClassName>’.
| Code | Message |
|---|---|
| 1093 | A class name was expected. |
| 1094 | A base class name is expected after the 'extends' keyword. |
| 1095 | A member attribute was used incorrectly. |
| 1096 | The same member name may not be repeated more than once. |
| 1097 | All member functions need to have names. |
| 1099 | This statement is not permitted in a class definition. |
| 1100 | A class or interface has already been defined with this name. |
| 1101 | Type mismatch. |
| 1102 | There is no class with the name ''. |
| 1103 | There is no property with the name ''. |
| 1104 | A function call on a non-function was attempted. |
| 1105 | Type mismatch in assignment statement: found [lhs-type] where [rhs-type] is required. |
| 1106 | The member is private and cannot be accessed. |
| 1107 | Variable declarations are not permitted in interfaces. |
| 1108 | Event declarations are not permitted in interfaces. |
| 1109 | Getter/setter declarations are not permitted in interfaces. |
| 1110 | Private members are not permitted in interfaces. |
| 1111 | Function bodies are not permitted in interfaces. |
| 1112 | A class may not extend itself. |
| 1113 | An interface may not extend itself. |
| 1114 | There is no interface defined with this name. |
| 1115 | A class may not extend an interface. |
| 1116 | An interface may not extend a class. |
| 1117 | An interface name is expected after the 'implements' keyword. |
| 1118 | A class may not implement a class, only interfaces. |
| 1119 | The class must implement method 'methodName' from interface 'interfaceName'. |
| 1120 | The implementation of an interface method must be a method, not a property. |
| 1121 | A class may not extend the same interface more than once. |
| 1122 | The implementation of the interface method doesn't match its definition. |
| 1123 | This construct is only available in ActionScript 1.0. |
| 1124 | This construct is only available in ActionScript 2.0. |
| 1125 | Static members are not permitted in interfaces. |
| 1126 | The expression returned must match the function's return type. |
| 1127 | A return statement is required in this function. |
| 1128 | Attribute used outside class. |
| 1129 | A function with return type Void may not return a value. |
| 1130 | The 'extends' clause must appear before the 'implements' clause. |
| 1131 | A type identifier is expected after the ':'. |
| 1132 | Interfaces must use the 'extends' keyword, not 'implements'. |
| 1133 | A class may not extend more than one class. |
| 1134 | An interface may not extend more than one interface. |
| 1135 | There is no method with the name ''. |
| 1136 | This statement is not permitted in an interface definition. |
| 1137 | A set function requires exactly one parameter. |
| 1138 | A get function requires no parameters. |
| 1139 | Classes may only be defined in external ActionScript 2.0 class scripts. |
| 1140 | ActionScript 2.0 class scripts may only define class or interface constructs. |
| 1141 | The name of this class, '', conflicts with the name of another class that was loaded, ''. |
| 1142 | The class '' could not be loaded. |
| 1143 | Interfaces may only be defined in external ActionScript 2.0 class scripts. |
| 1144 | Instance variables cannot be accessed in static functions. |
| 1145 | Class and interface definitions cannot be nested. |
| 1146 | The property being referenced does not have the static attribute. |
| 1147 | This call to super does not match the superconstructor. |
| 1148 | Only the public attribute is allowed for interface methods. |
| 1149 | The import keyword cannot be used as a directive. |
| 1150 | You must export your movie as Flash 7 to use this action. |
| 1151 | You must export your movie as Flash 7 to use this expression. |
| 1152 | This exception clause is placed improperly. |
| 1153 | A class must have only one constructor. |
| 1154 | A constructor may not return a value. |
| 1155 | A constructor may not specify a return type. |
| 1156 | A variable may not be of type Void. |
| 1157 | A function parameter may not be of type Void. |
| 1158 | Static members can only be accessed directly through classes. |
| 1159 | Multiple implemented interfaces contain same method with different types. |
| 1160 | There is already a class or interface defined with this name. |
| 1161 | Classes, interfaces, and built-in types may not be deleted. |
| 1162 | There is no class with this name. |
| 1163 | The keyword '' is reserved for ActionScript 2.0 and cannot be used here. |
| 1164 | Custom attribute definition was not terminated. |
| 1165 | Only one class or interface can be defined per ActionScript 2.0 .as file. |
| 1166 | The class being compiled, '', does not match the class that was imported, '' |
| 1167 | You must enter a class name. |
| 1168 | The class name you have entered contains a syntax error. |
| 1169 | The interface name you have entered contains a syntax error. |
| 1170 | The base class name you have entered contains a syntax error. |
| 1171 | The base interface name you have entered contains a syntax error. |
| 1172 | You must enter an interface name. |
| 1173 | You must enter a class or interface name. |
| 1174 | The class or interface name you have entered contains a syntax error. |
| 1175 | 'variable' is not accessible from this scope. |
| 1176 | Multiple occurrences of the 'get/set/private/public/static' attribute were found. |
| 1177 | A class attribute was used incorrectly. |
| 1178 | Instance variables and functions may not be used to initialize static variables. |
| 1179 | Runtime circularities were discovered between the following classes:%1 |
| 1180 | The currently targeted Flash Player does not support Debugging. |
| 1181 | The currently targeted Flash Player does not support the releaseOutside event. |
| 1182 | The currently targeted Flash Player does not support the dragOver event. |
| 1183 | The currently targeted Flash Player does not support the dragOut event. |
| 1184 | The currently targeted Flash Player does not support dragging actions. |
| 1185 | The currently targeted Flash Player does not support the loadMovie action. |
| 1186 | The currently targeted Flash Player does not support the getURL action. |
| 1187 | The currently targeted Flash Player does not support the FSCommand action. |
| 1188 | Import statements are not allowed inside class or interface definitions. |
| 1189 | The class '' cannot be imported because its leaf name is already being resolved to the class that is being defined, ''. |
| 1190 | The class '' cannot be imported because its leaf name is already being resolved to imported class ''. |
| 1191 | A class's instance variables may only be initialized to compile-time constant expressions. |
| 1192 | Class member functions cannot have the same name as a superclass's constructor function. |
| 1193 | The name of this class, '', conflicts with the name of another class that was loaded. |
| 1194 | The superconstructor must be called first in the constructor body. |
| 1195 | The identifier '' will not resolve to built-in object '' at runtime. |
| 1196 | The class '' needs to be defined in a file whose relative path is <'A.B>'. |
| 1197 | The wildcard character '*' is misused in the ClassName ''. |
| 1198 | The member function '' has a different case from the name of the class being defined, '', and will not be treated as the class constructor at runtime. |
| 1199 | The only type allowed for a for-in loop iterator is String. |
| 1200 | A setter function may not return a value. |
| 1201 | The only attributes allowed for constructor functions are public and private. |
| 1202 | The file 'toplevel.as', which is required for typechecking ActionScript 2.0, could not be found. Please make sure the directory '$(LocalData)/Classes' is listed in the global classpath of the ActionScript Preferences. (Flash 8) |
| 1203 | Branch between <spanStart> and <spanEnd> exceeds 32K span. (Flash 8) |
| 1204 | There is no class or package with the name '' found in package ''. (Flash 8) |
| 1205 | The currently targeted Flash Player does not support the FSCommand2 action. (Flash 8) |
| 1206 | Member function '' is larger than 32K. (Flash 8) |
| 1207 | Anonymous function around line <lineNumber> exceeds 32K span. (Flash 8) |
| 1208 | Code around line <lineNumber> exceeds 32K span. (Flash 8) |
| 1210 | The package name '' cannot also be used as a method name. (Flash 8) |
| 1211 | The package name '' cannot also be used as a property name. (Flash 8) |
| 1212 | The ASO file for the class '' could not be created. Please make sure the fully-qualified class name is short enough so that the ASO filename, '<ClassName.aso>', is less than 255 characters. (Flash 8) |
| 1213 | This type of quotation mark is not allowed in ActionScript. Please change it to a standard (straight) double quote. (Flash 8) |
Syntax errors in the code itself are reported as in ActionScript 1.0.
The checks end there. Anything the annotations do not cover, untyped values, bracket access and timeline paths, is left to fail or succeed when the movie runs.
What a class becomes
For each class it compiles, Flash adds a movie clip symbol to the SWF named
__Packages. and the class’s full name, such as
__Packages.com.example.Volume, exported but never placed. The class code
goes in a DoInitAction tag for that symbol, in the export frame, so it runs
once before that frame’s scripts, superclasses before subclasses. In outline, as a
decompiler shows it, the code is:
if (!_global.com) { _global.com = new Object(); }
if (!_global.com.example) { _global.com.example = new Object(); }
if (!_global.com.example.Volume) {
var v1 = function () { … }; // the constructor
com.example.Volume = v1;
com.example.Volume extends MovieClip; // only if the class extends one
var v2 = v1.prototype;
v2.setLevel = function (n) { … }; // each method
v2.__get__percent = function () { … }; // get percent
v2.__set__percent = function (value) { … };
v2.addProperty("percent", v2.__get__percent, v2.__set__percent);
ASSetPropFlags(com.example.Volume.prototype, null, 1);
}
for..in.- The guard
if (!_global…)means a class already defined, for example by a movie loaded earlier, is not replaced. - Methods and starting values of variables go on the prototype; static members on the constructor.
- A getter without a setter is given an empty function as its setter. Where the
compiler knows an object’s type, it may call
__get__name()directly instead of reading the property. - The
extendsline is theExtendsaction of SWF 7, which links the prototypes and records the superclass constructor forsuper. - A symbol whose linkage names an ActionScript 2.0 class gets its own
DoInitActionwithObject.registerClass("linkage name", com.example.Ball). - Types,
publicandprivateare gone; names of members and classes remain as strings.
Flash Player 7 actions
Publishing for Flash Player 7 or later lets the compiler use the actions SWF 7 added for this language:
| Action | Used for |
|---|---|
DefineFunction2 | Every function and method: locals, parameters, this, arguments, super, _root, _parent and _global kept in registers where possible, which is faster |
Extends | class … extends |
ImplementsOp | implements |
CastOp | Casts to classes and interfaces, giving null on failure |
Try, Throw | try, catch, finally and throw |
For Flash Player 6 these actions do not exist: functions use the older
DefineFunction, and exceptions cannot be used. The actions and the tags are
described in ActionScript in SWF, and where scripts are
kept in the document on the FLA pages.