Introduction
This is the uncompressed Flash movie of Flash MX and every version since: SWF 6, from March 2002, to the SWF 51 of today’s AIR SDK. It holds vector shapes, bitmaps, sounds, video, text and scripts, laid out frame by frame. The format is documented in Adobe’s SWF File Format Specification, whose last edition, version 19, came out in January 2013. Movies are made with Adobe Animate, formerly Flash Professional, and the compilers of the AIR and Apache Flex SDKs.
SWF 6 changed two things that were already in the file, so the movies before it are
a separate format. Every string is UTF-8, where SWF 1 to 5 used the code page of the
computer playing the movie. And the clip event flags of placed objects grew from 16
to 32 bits. Everything that came after only added: video tags, ActionScript 2.0
classes (SWF 7), filters, blend modes and the FileAttributes tag (SWF 8),
and ActionScript 3.0 in ABC bytecode for the AVM2 (SWF 9). Many SWF 6 and later movies
are compressed with zlib or LZMA, which makes them separate formats too; this page is
the form without compression.
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 and the AVM2 code.
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, 6 or more4 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 body; from SWF 8 the first is FileAttributesto the End tag
A real file
The start of a SWF 6 movie of 7,541 bytes, a 550 × 400 pixel stage at 12 frames a
second with one frame. The header is marked; then a SetBackgroundColor
tag (white) and a DoAction tag in the long form, whose actions begin
with a constant pool of 84 strings.
00000000 46 57 53 06 75 1D 00 00 78 00 05 5F 00 00 0F A0
00000010 00 00 0C 01 00 43 02 FF FF FF 3F 03 51 1D 00 00
00000020 88 E4 01 54 00 74 68 69 73 00 6E 6F 72 6D 61 6C
FWS, SWF 6, 7,541 bytes; then tags from offset 0x15Characters and the timeline
Definition tags create characters (shapes, bitmaps, fonts, text, sounds, buttons,
sprites, videos), 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, DoInitAction, buttons and clip events, or, from
SWF 9, an ABC file in a DoABC tag for the AVM2.
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, strings, colours, RECT, MATRIX and CXFORM
- Tag codes – every tag code, its version and where it is described
- Control tags – End, SetBackgroundColor, FileAttributes, SymbolClass, ExportAssets and the other tags about the whole movie
- Display list and frames – PlaceObject, PlaceObject2 and 3, RemoveObject, ShowFrame, sprites, frame labels, clip actions and filters
- Shapes – DefineShape 1 to 4, morph shapes, fill and line styles, gradients and shape records
- Bitmaps – JPEG, lossless and alpha bitmaps
- Sounds – event and streaming sounds, the sound formats and SWF ADPCM
- Fonts and text – DefineFont 1 to 4, font information, static text and text fields
- Buttons – DefineButton and DefineButton2, button records, condition actions and sounds
- Video – video characters and their frames
- AVM1 actions – the bytecode of ActionScript 1.0 and 2.0: every action, its operands and what it does
- ABC file – the DoABC tag and the ActionScript 3.0 bytecode file, field by field
- AVM2 instructions – every AVM2 opcode, its operands and its stack effect
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 6 or
more. 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. A version above 60 is read
but noted as newer than any known version.
An FWS file with version 1 to 5 is the older uncompressed format, and a
file starting CWS or ZWS is a compressed movie; each is a
separate format.
From SWF 8 the first tag should be FileAttributes. Some movies have
none, such as screen recordings that start with SoundStreamHead2; they
still play, and the explorer notes the missing tag.
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, for AVM1 and AVM2 code (Windows, macOS, Linux)
- Adobe Animate – Adobe’s authoring tool, formerly Flash Professional, which exports SWF; now in maintenance mode (Windows, macOS)
- AIR SDK – the AIR runtime and SDK, maintained by Harman since 2019, which compiles and packages SWF content (Windows, macOS, Linux)
- Apache Flex SDK – open-source SDK with the
mxmlcandcompccompilers; last release 4.16.1, 2017 (Windows, macOS, Linux) - SWFTools – command-line tools such as
swfdump,swfcandpdf2swf - Lightspark – open-source Flash player, still in alpha
- Flasm – command-line AVM1 assembler and disassembler, version 1.62 of 2007
Developers
- Ruffle source – Ruffle’s code, whose
swfcrate reads and writes SWF files (Rust) - avmplus – Adobe’s published source of the AVM2, with the ABC parser and opcode table (C++)
- Haxe – a language whose compiler still writes SWF, with regression fixes only
Reference
- SWF File Format Specification, version 19 – Adobe’s last edition, January 2013, as archived (PDF)
- SWF specification mirror – the same document, mirrored by the Open Flash project (PDF)
- ActionScript Virtual Machine 2 (AVM2) Overview – Adobe’s May 2007 description of the AVM2 and the ABC format, as archived (PDF)
- SWF version chart – Ruffle’s table of SWF versions, players and AIR releases