Is it text?
Yes. A script typed into the Actions panel is stored as its source text, exactly as typed, with its comments, tabs and line breaks (CR LF or LF), in UTF-16LE. Every script in the documents of this format examined for this site is stored this way. The languages are ActionScript 1.0 and ActionScript 2.0 from Flash MX 2004, and ActionScript 3.0 from Flash CS3; the document’s publish settings say which one it is compiled as.
The script is never compiled in the .fla. Flash turns it into AVM1 actions
or, for ActionScript 3.0, AVM2 bytecode only when it publishes the SWF; see
ActionScript in SWF. Classes are not in
the document at all: they are .as files, which the document only names
(see Classes).
The ActionScript block
Every keyframe and every movie clip and button instance carries an ActionScript block, even when it has no script. All fields are little-endian.
| Field | Present | Meaning |
|---|---|---|
| u32 | always | The block’s revision: 4 in Flash MX 2004 and Flash 8, 5 in CS3 and CS4. |
| u32 | always | The mode. 1: source text follows. Modes 0 (a normal-mode statement list) and 2 (nothing) were seen only in Flash MX and earlier documents. |
| u32 | always | An identifier; its meaning is not established. |
| u32 n, then n × u32 | always | Breakpoints: the line numbers where the debugger stops. |
| u32 m, then m × u32 | from revision 5 | Collapsed code ranges: pairs of offset and length, for the parts of the script folded away in the editor. |
| CString | always | The script, in the Unicode form: FF FE FF, the length in characters, then UTF-16LE. See strings. |
The names of the fields and the meaning of the modes come from the JPEXS FLA converter, and were checked against files here. The converter also reads a block revision 3, whose script is a CString length followed by UTF-16LE with no marker; no file with revision 3 has been seen.
04 00 00 00 01 00 00 00 84 67 00 00 00 00 00 00
FF FE FF 06 73 00 74 00 6F 00 70 00 28 00 29 00 ....s.t.o.p.(.).
0x6784, no breakpoints, then the script stop()1D 01 00 00 26 … FF FF FF 3F FF FF FF FE FF 00
05 00 00 00 01 00 00 00 42 44 00 00 00 00 00 00 00 00 00 00
FF FE FF F9 2F 00 2F 00 …
P 1 1227523356: frame revision 0x1D, a duration of 1, key mode 0x2600, an empty label; then block revision 5, mode 1, identifier 0x4442, no breakpoints, no collapsed ranges, and a script of 249 characters that starts //Frame scripts
A frame script is the block in a frame record, right after the frame label. Where it belongs is worked out from where the record sits:
- The timeline is the stream.
Contentsgives the scene or symbol name for it, such asScene 1forPage 1. - The layer is the layer record whose children include the frame. Its name follows the last of its frames, so a reader has to read on, or come back to it.
- The frame number is 1 plus the durations of the layer’s earlier keyframes. A keyframe with a duration of 7 at frame 2 covers frames 2 to 8.
Worked out this way, the scripts of a Flash CS4 document matched those of its XFL
copy, saved by a later release: an [actionscript] layer with scripts on
frames 1, 2 to 8, 9 to 15 and 16 to 22. The explorer heads each script with exactly
this, for example Scene 1 (Page 1), layer "Actions", frame 9–10 "label" · offset
0x17D in stream "Page 1".
Instance handlers
ActionScript 1.0 and 2.0 let a script sit on a button or a movie clip placed on the
stage, instead of on a frame. It is written as handlers, on (…) for
buttons and movie clips and onClipEvent (…) for movie clips:
on(release)
{
_root.gotoAndStop(2)
}
These are stored in the instance’s own record, on the frame where the instance sits, not in the frame’s block:
- A movie clip (
CPicSprite): the sprite revision, the ActionScript block, then the instance name. - A button (
CPicButton): the button revision, the ActionScript block, a track-as-menu byte, then the instance name.
ActionScript 3.0 does not allow scripts on instances; its documents keep their code in frame scripts and classes. The explorer labels instance scripts with the instance name, or as an unnamed instance, and the timeline, layer and frame where the instance is. See Symbol instances.
Classes and the document class
ActionScript 2.0 and 3.0 classes live in .as files, not in the FLA. Each
is found through the classpath: a class classes.SimpleMMOWorld is the file
classes/SimpleMMOWorld.as under one of the classpath folders, where
. is the FLA’s own folder. The document only names classes, in two
places:
- The linkage of a library symbol: the class a movie clip symbol is exported as. If no
.asfile of that name exists, Flash generates the class when it publishes. - The document class, Flash CS3 and CS4 only: the ActionScript 3.0 class of the main
timeline, kept in the publish settings in
ContentsasVector::DocumentClass(for exampleAvatarChat, inAvatarChat.as). The ActionScript 3.0 classpath isVector::AS3 Package Paths.
A document whose .as files are lost cannot be published as it was. The
explorer shows the document class and where its file would be. See
the ActionScript 2.0 classpath and
the ActionScript 3.0 document
class.
Included files
An ActionScript 1.0 or 2.0 script can pull in another file when the document is published:
#include "Script.as"
.as fileThe #include line is all the .fla holds; the file stays
beside the document. ActionScript 3.0 has the same directive without the
#, include "file.as". The explorer lists every
#include it finds in the scripts.
Documents that mix encodings
Flash rewrites only the streams that changed when it saves. A document first made in
Flash MX and last saved in Flash 8 can therefore have a Flash 8 Contents
(revision 0x3F, UTF-16) and a symbol stream still as Flash MX wrote it,
with Flash MX’s revisions and a single-byte script. Many such documents were
seen.
A reader has to take the revisions from each stream and each record, starting with the
byte after the class name CPicPage, not from the document revision, and
has to test every string for the FF FE FF marker. The explorer does both,
and marks scripts read from such a stream as single-byte text.
Older copies in free sectors
Because an ordinary save leaves the old sectors in place, marked free, earlier versions
of scripts often survive in the free
sectors until the document is saved with Save and Compact. In one Flash 8 document
the current button handler calls _root.gotoAndStop(2), while a free sector
still holds the older one, which called gotoAndStop(2). The explorer
searches free and unreached sectors for script blocks and lists what it finds
separately, as older copies that are not part of the document, with the sectors they
are in.
What the explorer shows
- Every script in the file as one text, each headed by where it is: the timeline, the layer, the frame range and label, or the instance, and the offset in its stream.
- A Scripts table: timeline, layer, frame or instance, label, offset, number of lines and first line. A row opens the sector that holds the script.
- The ActionScript version, the document class and the included files.
- The older scripts found in free sectors, separately.