The compiler turns ActionScript 3.0 into ABC (ActionScript Byte Code), the format the AVM2 runs, and stores it in the SWF. This page follows the source through to the bytes: what each construct becomes. The full SWF and ABC layout, every field and every instruction, is on the SWF pages: ABC file and AVM2 instructions. The facts here come from Adobe’s AVM2 overview and the ABC notes published with its virtual machine.
In the SWF
| Tag | Code | What the compiler puts in it |
|---|---|---|
FileAttributes | 69 | The first tag. Its ActionScript 3.0 flag tells the player to run the file’s code on the AVM2; a SWF has either AVM2 or AVM1 code, never both. |
ScriptLimits | 65 | The recursion limit and the script time limit, from [SWF] or the publish settings. |
SetBackgroundColor | 9 | The stage colour. |
DoABC | 82 | A 32-bit flags field (1 means initialise lazily), a name string, then one complete ABC file. A SWF may hold several, in one frame or spread over frames. |
| DoABC without flags | 72 | An older form of the tag, holding only the ABC file. |
SymbolClass | 76 | Pairs of a character ID and a full class name: the class linked to each library symbol, and for ID 0 the document class or generated main timeline class. |
FrameLabel | 43 | Frame labels, including the ones mxmlc gives the frames of a two-frame application. |
When the player reaches a DoABC tag it loads the ABC, links its classes
into the SWF’s application domain and runs the entry script; the frame’s
SymbolClass entries then attach classes to symbols. The main timeline is
an instance of the class for ID 0, created first.
The ABC file
An ABC file is a sequence of tables. Most numbers are variable-length
u30 values: 7 bits per byte, low bits first, with the top bit set on every
byte but the last, up to 5 bytes. Every pool leaves index 0 unused, so a count of
n means n−1 entries, and index 0 in a reference means “none” or
“any”.
| Part | Holds |
|---|---|
minor_version, major_version | u16 each, little-endian: 16 and 46, the version Flash Player 9 introduced. |
| Constant pool | Integers (s32), unsigned integers (u32), doubles (8 bytes), strings (a u30 length and UTF-8 bytes), namespaces, namespace sets and multinames, in that order, each with a count. |
method_info[] | One signature per method, function, getter, setter, constructor and initialiser. |
metadata_info[] | The metadata tags that were kept. |
instance_info[], class_info[] | One pair per class or interface, with the same count. |
script_info[] | One per compiled script; the last is the entry point. |
method_body_info[] | The code of every method that has a body. |
Namespaces
Every name in ABC is qualified by a namespace, and the access attributes of the source become namespace kinds.
| Kind | Value | Made from |
|---|---|---|
PackageNamespace | 0x16 | public: named after the package for package-level definitions, such as com.example.shapes; the empty string is the public namespace of class members and the top level. |
PackageInternalNs | 0x17 | internal, named after the package. |
PrivateNs | 0x05 | private: a namespace no other class can share, one per class, and one for the file-level definitions after a package block. |
ProtectedNamespace | 0x18 | protected, one per class, named after it. |
StaticProtectedNs | 0x1A | protected static members. |
Namespace | 0x08 | A user-defined namespace, by its URI; also AS3 and flash_proxy. |
ExplicitNamespace | 0x19 | A namespace written out explicitly. |
A namespace set lists several namespaces, which is how the compiler records the
namespaces open at a reference whose namespace it cannot fix: every
imported package, the public namespace and any opened with
use namespace.
Multinames
| Kind | Value | Used for |
|---|---|---|
QName, QNameA | 0x07, 0x0D | A name in one namespace: every definition, and references the compiler resolved. The A forms are XML attributes (@). |
Multiname, MultinameA | 0x09, 0x0E | A name searched in a namespace set, for references resolved at run time. |
RTQName, RTQNameA | 0x0F, 0x10 | ns::name where ns is a value known only at run time. |
RTQNameL, RTQNameLA | 0x11, 0x12 | ns::[expr]: both the namespace and the name at run time. |
MultinameL, MultinameLA | 0x1B, 0x1C | obj[expr]: a computed name in a namespace set. |
TypeName | 0x1D | A type with parameters: Vector.<int>. Added after the first ABC description, for Flash Player 10. |
Classes and interfaces
Each class or interface becomes an instance_info and a
class_info at the same index.
| Field | From the source |
|---|---|
instance_info.name | The class’s QName: package namespace and class name. |
super_name | The extends class; Object when there is none; 0 for an interface. |
flags | 0x01 sealed (not dynamic), 0x02 final, 0x04 interface, 0x08 has a protected namespace, given in protectedNs. |
interface[] | The implements list (for an interface, its extends list). |
iinit | The constructor, as a method; the compiler adds the field initialisers and the super() call to it. |
instance_info.traits | The instance variables, constants, methods, getters and setters. |
class_info.cinit | The static initialiser: static variable values and statements in the class body. |
class_info.traits | The static members. |
Traits
A trait is one fixed property: a name (a QName) and a kind in the low 4 bits of a byte whose high 4 bits hold attributes.
| Kind | Value | Made from |
|---|---|---|
Slot | 0 | var: a slot number, a type and an optional constant initial value. |
Method | 1 | A method. |
Getter | 2 | function get. |
Setter | 3 | function set. |
Class | 4 | A class defined by a script. |
Function | 5 | A function in a slot. |
Const | 6 | const: like a slot, but cannot be reassigned. |
| Attribute bit | Value in the kind byte | Made from |
|---|---|---|
| Final | 0x10 | final on a method. |
| Override | 0x20 | override. |
| Metadata | 0x40 | Kept metadata follows the trait, as indexes into metadata_info. |
Dynamic properties, prototype properties and the members of a dynamic class added at run time have no traits: they live in each object’s hash table and are found by name.
Methods
A method_info is the signature: the parameter count, the return type
and each parameter type as multinames (0 for *), a name, a flags byte, the
default values of optional parameters and, if kept, the parameter names.
| Flag | Value | Set when |
|---|---|---|
NEED_ARGUMENTS | 0x01 | The body uses arguments. |
NEED_ACTIVATION | 0x02 | Locals must live in an activation object, because a nested function or with captures them. |
NEED_REST | 0x04 | There is a ...rest parameter. |
HAS_OPTIONAL | 0x08 | Some parameters have default values, which follow. |
IGNORE_REST | 0x10 | Extra arguments are allowed and ignored; used by the runtime’s own classes. |
NATIVE | 0x20 | The method is native and has no body; only the runtime’s own classes use it. |
SET_DXNS | 0x40 | The body uses default xml namespace. |
HAS_PARAM_NAMES | 0x80 | Parameter names follow (debug builds). |
A method_body_info holds the code: the method it belongs to, the
maximum operand stack depth, the number of local registers (register 0 is
this, then the parameters, then the locals), the scope depths, the
instruction bytes, an exception table with one entry per catch (a start,
an end, a target, the caught type and the variable name), and the traits of the
activation object. Interface methods and native methods have no body.
// public function area():Number { return Math.PI * _radius * _radius; }
getlocal0 // this
pushscope
getlex Math
getproperty PI
getlocal0
getproperty private::_radius
multiply
getlocal0
getproperty private::_radius
multiply
returnvalue
Scripts, packages and frame scripts
- Each script has an initialiser method and traits for the definitions it makes. The compiler usually writes one script per source file: its traits are the file’s package-level class, function or variable and its helper definitions, and its initialiser builds the classes (with
newclass) and runs package-level statements. - A script runs the first time one of its definitions is needed, and the last script in the file runs at once, as the entry point.
- A package exists only as the namespace on these names; there is no package object.
- Frame scripts from Flash become methods
frame1,frame2… of the timeline’s class, and its constructor callsaddFrameScriptwith them. See Timelines and frame scripts. - Debug builds add
debugfileanddebuglineinstructions, which give stack traces their file names and line numbers.
Metadata
A kept metadata tag becomes a metadata_info: a name and a list of
key and value strings, with key index 0 for a value without a key. A trait with the
metadata bit lists the indexes of its tags. [Bindable] on a property,
for example, is kept by default; most tags are not (see
Which tags reach the SWF).