Introduction
An .as file holds ActionScript, the programming language of Flash, as plain
text. ActionScript was made by Macromedia for Flash 5 in 2000, and passed to Adobe when
it bought Macromedia in 2005. It is based on ECMAScript, the standard behind JavaScript.
Scripts are written in the Flash authoring program, now
Adobe Animate, and in the Flex
SDK, now Apache Flex, and are compiled into
SWF files for Flash Player and Adobe AIR.
Three different languages have used the extension. ActionScript 1.0 and 2.0 compile to
the same bytecode, but 2.0 changed what an .as file is: one class per file,
found by its name, instead of loose code pasted in. ActionScript 3.0 is a new language
for a new virtual machine. Versions that only add to a language share a format here; a
version that changes how an existing file is read is a separate format, so each of the
three has its own complete language reference.
An .as file dropped on any page opens in the explorer as text, and the
explorer tells the three languages apart.
Variations
| Format | Variation | About | Open |
|---|---|---|---|
.AS | ActionScript 1.0 | ActionScript 1.0 source: loose code pulled in by #include, with prototype-based objects. | Open |
.AS | ActionScript 2.0 | ActionScript 2.0 source: one class or interface per file, compiled to AVM1 actions. | Open |
.AS | ActionScript 3.0 | ActionScript 3.0 source: a package with one public class, compiled to ABC for the AVM2. | Open |
ActionScript 1.0
The language of Flash 5 and Flash MX (2000 to 2002). An .as file is a
piece of loose code, frame script in all but name, that a script in the Flash document
pulls in with #include "file.as"; the compiler pastes it in at that point.
Objects are built from constructor functions and prototypes. The event handlers
on() and onClipEvent() are attached to buttons and movie
clips inside the FLA file, never written in an .as file.
The file is a list of statements and function definitions, with no
class or package around them. It may hold
#include lines of its own, and in Flash MX it may start with the comment
//!-- UTF8. An .as file of loose code is this kind,
whichever version of Flash later included it.
ActionScript 2.0
The language of Flash MX 2004 to Flash CS4 (2003 to 2008), and of Flex 1. Each
.as file holds exactly one class or interface, named after the file and
found by the compiler through the classpath, with folders standing for packages. It
adds type annotations checked when compiling, but compiles to the same Flash Player
bytecode as ActionScript 1.0.
After any comments and import lines, the file’s code is a single
class or interface declaration at the top level, perhaps
with dynamic or intrinsic before it, and with a dotted name
such as class com.example.Menu when it is in a package.
ActionScript 3.0
The language of Flash CS3 and Flex 2 onwards (2006 to today, with Apache Flex,
Adobe AIR and Adobe Animate). Each .as file holds one
package block, which contains one public class, interface, function,
variable or namespace named after the file. It is a stricter language with its own
virtual machine, the AVM2, and does not run on the players that run ActionScript 1.0
and 2.0.
The file’s code starts with package, perhaps followed by a dotted
name, and an opening brace; everything else is inside that block, except private
helper classes after it.
Versions
The releases that changed ActionScript, with the language each one writes. Flash
versions before Flash 5 had a smaller set of actions, chosen from menus, and no
.as files.
| Release | Released | Player | ActionScript written |
|---|---|---|---|
| Flash 4 | 1999 | Flash Player 4 | Flash 4 actions: slash syntax paths, tellTarget, string operators such as eq and add; not yet called ActionScript |
| Flash 5 | 2000 | Flash Player 5 | ActionScript 1.0, with dot syntax, objects and #include |
| Flash MX | March 2002 | Flash Player 6 | ActionScript 1.0, adding #initclip, _global, switch and event handler properties |
| Flash MX 2004 | September 2003 | Flash Player 7 | ActionScript 2.0, or 1.0 by choice in the publish settings |
| Flex 1.0 | March 2004 | Flash Player 7 | ActionScript 2.0, with MXML, compiled on the server |
| Flash 8 | September 2005 | Flash Player 8 | ActionScript 2.0, adding the flash.* classes for bitmaps, filters and file uploads |
| Flex 2 | June 2006 | Flash Player 9 | ActionScript 3.0 only |
| Flash CS3 | April 2007 | Flash Player 9 | ActionScript 3.0, or 2.0 and 1.0 for the older players |
| Adobe AIR 1.0 | February 2008 | AIR runtime | ActionScript 3.0 only |
| Flash CS4 | October 2008 | Flash Player 10 | ActionScript 3.0, or 2.0 and 1.0 |
| Flash CS5 | April 2010 | Flash Player 10.x | ActionScript 3.0, or 2.0 |
| Flash CS5.5 | May 2011 | Flash Player 10.x | ActionScript 3.0, or 2.0 |
| Flash CS6 | May 2012 | Flash Player 11.x | ActionScript 3.0, or 2.0; the last version to compile ActionScript 2.0 |
| Apache Flex 4.8 | 2012 | Flash Player and AIR | ActionScript 3.0; the Flex SDK after Adobe gave it to the Apache Software Foundation |
| Flash Professional CC | June 2013 | Flash Player 11 and later | ActionScript 3.0 only |
| Adobe Animate CC | February 2016 | Flash Player, AIR | ActionScript 3.0; Flash Professional renamed |
| Harman AIR | 2019 | AIR runtime | ActionScript 3.0; Adobe passed AIR to Harman |
Adobe ended Flash Player on 31 December 2020. ActionScript 3.0 lives on in AIR applications and Animate; files in all three languages still play in emulators such as Ruffle.
Where ActionScript is stored
ActionScript is kept in three places: in .as text files, inside the
Flash document that holds the artwork, and, compiled, inside the SWF file that is
played.
In .as files
An .as file is plain text with no header or signature. Its encoding
depends on the program that wrote it:
- Flash 5 read and wrote ActionScript in the system’s own code page: Latin-1 on Western systems and Shift-JIS on Japanese ones. Flash Player 5 had no Unicode support.
- Flash MX read an included file in the system code page too, unless the file
started with the comment
//!-- UTF8and was saved as UTF-8; then the text was read as UTF-8. Flash Player 6 stores text as Unicode, so this was the way to get other scripts into a movie. - Flash MX 2004 and later have an ActionScript preference for opening and importing
and another for saving and exporting
.asfiles, each either UTF-8 or Default Encoding, the system’s traditional code page, and can warn about encoding conflicts when exporting. - The Flex and AIR compilers use the byte order mark when a file has one. Without
one they assume the computer’s default encoding unless told otherwise with the
-actionscript-file-encodingoption.
An .as file met today may therefore be UTF-8, with or without a byte
order mark, or in an older code page such as Windows-1252 or Shift-JIS, and nothing
in the file says which.
In .fla files
Most ActionScript 1.0 and much ActionScript 2.0 was never in an .as
file at all. It was typed in the Actions panel and saved inside the Flash document:
frame scripts on keyframes, on() handlers on buttons and movie clips,
onClipEvent() handlers on movie clips, and #initclip blocks
in symbols. ActionScript 3.0 documents keep frame scripts there and can also name a
document class, an .as file. From Flash 5 the scripts are kept as source
text: single-byte text up to Flash MX, UTF-16 text from Flash MX 2004 to CS4, and
<script> elements in the XML of a CS5 and later document. Flash 5
and MX could also keep a script as a list of statements built in the panel’s normal
mode, and Flash 1 to 4 kept actions as commands, not text. The details are in
ActionScript in FLA.
Compiled in .swf files
A SWF file never holds the source text. ActionScript 1.0 and 2.0 are compiled to
AVM1 bytecode, called actions: frame scripts go into DoAction tags,
#initclip blocks and ActionScript 2.0 classes into
DoInitAction tags (from SWF 6), and button and clip handlers into the
records of the DefineButton2 and PlaceObject2 tags that
place them. ActionScript 3.0 is compiled to ABC bytecode for the AVM2, stored in
DoABC tags. Names survive compiling, as strings, so a decompiler can
recover readable code; comments, formatting and ActionScript 2.0’s type annotations do
not. The tags and the bytecode are described in
ActionScript in SWF.
Links
Software
- Adobe Animate – Adobe’s animation program, formerly Flash Professional, which edits and compiles ActionScript 3.0 (Windows, macOS)
- Apache Flex SDK – the free Flex SDK and its command-line ActionScript 3.0 compiler (Windows, macOS, Linux)
- FlashDevelop – free code editor for ActionScript 2.0 and 3.0 (Windows)
- JPEXS Free Flash Decompiler – free tool that decompiles and edits the ActionScript in SWF files, in all three languages (Windows, macOS, Linux)
- Ruffle – free Flash Player emulator that runs compiled ActionScript (web browser, Windows, macOS, Linux)
Reference
- Flash MX 2004 Documentation – Adobe’s page for Macromedia’s ActionScript Language Reference and Using ActionScript in Flash, covering ActionScript 1.0 and 2.0
- ActionScript 2.0 Language Reference – Adobe’s reference for Flash CS5, in the Open Flash project’s mirror
- ActionScript 3.0 Reference for the Adobe Flash Platform – Adobe’s reference for every ActionScript 3.0 class
- ECMA-262, 3rd edition – the 1999 ECMAScript standard, the base of ActionScript 1.0 (PDF)