Introduction
ActionScript 2.0 is the language of Macromedia Flash MX 2004 (2003) and Flash 8 (2005), and of Adobe Flash CS3 and CS4, which still offered it beside ActionScript 3.0; Flash CS5 and CS6 could still compile it. Flex 1.0 and 1.5 used it too. It added classes, interfaces, packages and type annotations to the ActionScript of Flash MX, following the class syntax proposed for ECMAScript 4 at the time. The compiler checks the types, then turns the classes into the same prototype-based code that ActionScript 1.0 would have used, so the result runs in Flash Player 6 and later.
What changed for .as files is how they are found and what they hold.
Each file holds exactly one class or interface, named after the file, and the compiler
finds it on its own through the classpath when code uses the name: no
#include is needed. Folders stand for packages, so the class
com.example.ui.Counter is the file
com/example/ui/Counter.as. Scripts in the FLA, frame code and button and
clip handlers, are still written as before, now with type annotations if wanted, and
loose-code .as files can still be included. An .as file
dropped on any page opens in the explorer as text.
A typical file
A class for a movie clip symbol whose linkage settings name it as the symbol’s
ActionScript 2.0 class. The file is com/example/ui/Counter.as, in a folder
on the classpath.
import mx.utils.Delegate;
class com.example.ui.Counter extends MovieClip {
private var count:Number = 0;
private var label_txt:TextField; // instances placed in the symbol
private var plus_btn:Button;
public function Counter() {
plus_btn.onRelease = Delegate.create(this, increment);
update();
}
public function get value():Number {
return count;
}
private function increment():Void {
count++;
update();
}
private function update():Void {
label_txt.text = String(count);
}
}
The language at a glance
| Part | In ActionScript 2.0 |
|---|---|
| The .as file | One class or interface per file, named after it; UTF-8 or the system code page by preference. |
| Lexical structure | Case-sensitive throughout; new keywords such as class, private and try. |
| Types and conversion | Optional annotations such as :Number, checked when compiling only; casts; the conversion rules of Flash Player 7. |
| Variables and scope | Typed var, class members, timeline variables and _global. |
| Operators | ActionScript 1.0’s, with : for types; the Flash 4 word operators deprecated. |
| Statements | Adds try, catch, finally and throw. |
| Functions | Typed parameters and return types, Void, and methods bound with Delegate. |
| Classes | class, extends, constructors, public and private, static, getters and setters, dynamic, intrinsic. |
| Interfaces | interface and implements, checked when compiling. |
| Packages and the classpath | Dotted names, folders, import, the global and document classpaths, ASO files. |
| Events | Handlers, listeners, EventDispatcher and MovieClipLoader. |
| Movie clips | Symbols bound to classes, depths, and Flash 8’s filters, blend modes and bitmap caching. |
| Built-in classes | The classes of Flash Player 6 to 8, including the flash.* packages of Flash 8. |
| Global functions | The global functions, properties and constants, with setTimeout from Flash 8. |
| Compiler | Publish settings, type errors, and the AVM1 code a class becomes. |
Flash MX 2004, Flash 8 and later
Each later version only added to ActionScript 2.0, so they are one format:
- Flash MX 2004 (Flash Player 7) brought the language itself, exceptions, the
Error,MovieClipLoader,ContextMenu,PrintJobandTextField.StyleSheetclasses, and the version 2 components withmx.events.EventDispatcher. Its 7.2 update addedmx.utils.Delegate. - Flash 8 (Flash Player 8) added the
flash.display,flash.filters,flash.geom,flash.net,flash.externalandflash.textpackages, blend modes, bitmap caching andsetTimeout. - Flash CS3 and CS4 added nothing to the language. Flash Player 9 and 10 run
ActionScript 2.0 in the same virtual machine as before, and add only a few
properties, such as
MovieClip.forceSmoothing.
Telling it apart
An .as file has no signature, so the language is told from the code. The
explorer reads the text, skips comments, white space and import lines, and
takes a file whose code is a class or interface declaration
at the top level, perhaps after dynamic or intrinsic, as
ActionScript 2.0. A file that starts with a package block is
ActionScript 3.0 instead, and loose code is ActionScript 1.0.
The class name gives the package and so the folder the file belongs in:
class com.example.ui.Counter should be Counter.as in
com/example/ui. An ActionScript 3.0 file puts the same name in two places,
package com.example.ui { public class Counter, and its members carry
public, protected or internal where
ActionScript 2.0 has only public and private.
Variants
- ActionScript 1.0 – loose code pulled in by
#include, with prototype-based objects (Flash 5 and Flash MX) - ActionScript 2.0 – one class or interface per file, found through the classpath, compiled for AVM1 (Flash MX 2004 to Flash CS4)
- ActionScript 3.0 – a package block with one public definition, compiled for the AVM2 (Flash CS3, Flex 2 and later)
Links
Software
- Macromedia Flash MX 2004 and Flash 8 – the authoring programs that compile ActionScript 2.0 (Windows, Mac OS X)
- Adobe Flash CS3 to CS6 – later versions that still compile it beside ActionScript 3.0; CS6 was the last (Windows, Mac OS X)
- MTASC – Motion-Twin’s free command-line ActionScript 2.0 compiler, faster and stricter than Flash’s (Windows, macOS, Linux)
- FlashDevelop – free code editor for ActionScript 2.0 and 3.0, which can compile ActionScript 2.0 with MTASC (Windows)
- JPEXS Free Flash Decompiler – decompiles ActionScript 2.0 classes from SWF files back to class files, and edits them (Windows, macOS, Linux)
- Ruffle – Flash Player emulator that runs movies compiled from ActionScript 2.0 (web browser, Windows, macOS, Linux)
Reference
- ActionScript 2.0 Language Reference – Adobe’s reference for Flash CS5, every class and language element with its player version, in the Open Flash project’s mirror
- Learning ActionScript 2.0 in Flash – Macromedia’s guide to the language for Flash 8, in the Open Flash project’s mirror (PDF)
- Flash MX 2004 Documentation – Adobe’s page for Macromedia’s ActionScript Language Reference and Using ActionScript in Flash for Flash MX 2004