Introduction
This is the Flash movie of the first five versions of the format: SWF 1, from FutureSplash Animator and Macromedia Flash 1 in 1996, to SWF 5, from Flash 5 in August 2000. It holds vector shapes, bitmaps, sounds, buttons, text and, from Flash 3, scripts, laid out frame by frame for the player. Adobe documented it in the SWF File Format Specification, whose last edition, version 19 of January 2013, still marks what each version added. Today these movies play in Ruffle.
Two things set these movies apart from later ones, and make them a separate format. Their text, from frame labels and text fields to every string in the scripts, is in the code page of the computer playing the movie, ANSI or Shift-JIS on Japanese systems, and nothing in the file says which. And the event flags of a movie clip’s handlers are 16 bits. SWF 6 changed both, to UTF-8 and 32 bits. There is no compression of the whole file, no video and no ActionScript 3: the scripts are AVM1 actions, the stack actions of Flash 4 and then the objects, functions and constant pool of Flash 5’s ActionScript.
A .swf file dropped on any page opens in the explorer, which draws the
frames, lists the tags and the characters, decodes the bitmaps and sounds, and
disassembles the AVM1 actions. It reads the text as Windows-1252.
Structure
A movie is a header followed by a run of tags up to an End tag. All numbers are little-endian, and many fields are packed into bits.
0Signature and versionFWS, then the SWF version, 1 to 54 bytes4FileLength the size of the whole file4 bytes8FrameSize the stage, a RECT in twipsusually 9 bytes…FrameRate and FrameCount frames a second, 8.8 fixed point, and the number of frames4 bytes…Tags definition and control tags, each a record header and a bodyto the End tag
A real file
The start of a Flash 4 movie, SWF 4, of 4,515 bytes: a 550 × 400 pixel stage at 30
frames a second with two frames. The header is marked; then a
SetBackgroundColor tag (white) and a DoAction tag in the
long form, whose 830 bytes of actions start with an ActionPush of the
string “xangle”.
00000000 46 57 53 04 A3 11 00 00 78 00 05 5F 00 00 0F A0
00000010 00 00 1E 02 00 43 02 FF FF FF 3F 03 3E 03 00 00
00000020 96 08 00 00 78 61 6E 67 6C 65 00
FWS, SWF 4, 4,515 bytes; then tags from offset 0x15Characters and the timeline
Definition tags create characters (shapes, bitmaps, fonts, text, sounds, buttons
and, from SWF 3, sprites), each with a 16-bit ID in the movie’s dictionary. Control
tags act on the display list: they place characters at depths, move and remove them,
and a ShowFrame tag ends each frame. Scripts are AVM1 actions in
DoAction tags, buttons and, from SWF 5, clip events.
Reference pages
- Header – the signature, version, file length, frame size, frame rate and frame count
- Tags and data types – the record header, the tag run, numbers, bit fields, code-page strings, colours, RECT, MATRIX and CXFORM
- Tag codes – every tag code, the version that brought it and where it is described
- Control tags – End, SetBackgroundColor, Protect, ExportAssets, ImportAssets and EnableDebugger
- Display list and frames – PlaceObject, PlaceObject2, RemoveObject, ShowFrame, sprites, frame labels and 16-bit clip actions
- Shapes – DefineShape 1 to 3, morph shapes, fill and line styles, gradients and shape records
- Bitmaps – JPEG, lossless and alpha bitmaps
- Sounds – event and streaming sounds, uncompressed, ADPCM and MP3
- Fonts and text – DefineFont, DefineFont2, font information, static text and text fields
- Buttons – DefineButton and DefineButton2, button records, condition actions and sounds
- AVM1 actions – the actions of Flash 3, 4 and 5: every action, its operands and what it does
Telling it apart
The explorer’s parser for this format checks that the file starts with
FWS (46 57 53) and that the version byte at offset 3 is
from 1 to 5. It then reads the header and walks the tag headers to the End tag; a tag
whose length runs past the end of the file turns the file down.
An FWS file with version 6 or more is the later uncompressed format, and
a file starting CWS or ZWS is a compressed movie; each is a
separate format. Nearly all the files of this format examined for this site are SWF 4
and SWF 5 movies; SWF 1, 2 and 3 movies are rare.
Variants
- Flash movie, SWF 1 to 5 (FWS) – the first SWF layout: an uncompressed movie whose text is in the player’s system code page
- Flash movie, SWF 6 and later (FWS) – text in UTF-8 and 32-bit clip event flags, uncompressed; the form ActionScript 3 movies also take
- Compressed Flash movie, zlib (CWS) – everything after the first 8 bytes is a zlib stream; inside is the same movie as an SWF 6 file
- Compressed Flash movie, LZMA (ZWS) – an LZMA-compressed movie: a compressed length and LZMA properties, then LZMA data
Links
Software
- Ruffle – open-source Flash Player emulator that plays SWF in the browser and on the desktop (Windows, macOS, Linux, web browser)
- JPEXS Free Flash Decompiler – open-source SWF decompiler and editor (Windows, macOS, Linux)
- SWFTools – command-line tools such as
swfdumpandswfc - Flasm – command-line AVM1 assembler and disassembler, version 1.62 of 2007
- Gnash – the GNU Flash player, mostly for SWF 7 and earlier, no longer developed
- Lightspark – open-source Flash player, still in alpha
Developers
- Ruffle source – Ruffle’s code, whose
swfcrate reads and writes SWF files (Rust)
Reference
- SWF File Format Specification, version 19 – Adobe’s last edition, January 2013, which marks what each version added, as archived (PDF)
- SWF specification mirror – the same document, mirrored by the Open Flash project (PDF)
- SWF version chart – Ruffle’s table of SWF versions and players