Made to Order Software Corporation Logo

SWF

SWF Type Definitions

This documents makes use of structure definitions that very much look like C structures. It is important to note that this is not all that true since the data saved in a SWF file are very specific and they don't follow the default, inflexible (as in static,) C definitions.

The following pages define the basic types used in this document. The comments explain in more details how each type is used.

Note that except for bit fields, all types start on a byte boundary. Nothing will be aligned on more than one byte.

DefineButton

Tag Info
Tag Number: 
7
Tag Type: 
Define
Tag Flash Version: 
1
Brief Description: 

Define an action button.

Tag Structure: 
struct swf_definebutton {
	swf_tag			f_tag;		/* 7 */
	unsigned short		f_button_id;
	swf_button		f_buttons;
	swf_action		f_actions;
};

Mouse interactivity in the SWF format comes from the buttons. All the buttons have an identifier and can be placed in the display list like any other shape.

A buttons has different states. Some states can be entered only when the button was in a specific state before (like a button being pushed).

Buttons can be represented graphically in any manner you want. Each state can use a different edit text, shape, sprite or text to render the button.

DefineBitsJPEG

Tag Info
Tag Number: 
6
Tag Type: 
Define
Tag Flash Version: 
1
Brief Description: 

Define a JPEG bit stream.

Tag Structure: 
struct swf_definebitsjpeg {
	swf_long_tag		f_tag;		/* 6, 21, 35 or 90 */
	unsigned short		f_image_id;
	if(f_tag == DefineBitsJPEG3 + f_tag == DefineBitsJPEG4) {
		/* sizeof(f_encoding_tables) + sizeof(f_image_data) + 2 when JPEG4 */
		unsigned long		f_offset_to_alpha;
	}
	if(f_tag == DefineBitsJPEG4) {
		unsigned short fixed	f_deblocking_filter_parameter;
	}
	if(f_tag != DefineBitsJPEG) {
		/* when DefineBitsJPEG, use JPEGTables instead */
		unsigned char		f_encoding_tables[<variable size>];
	}
	unsigned char		f_image_data[<variable size>];
	if(f_tag == DefineBitsJPEG3 || f_tag == DefineBitsJPEG41) {
		unsigned char		f_alpha[<variable size>];
	}
};
  • 1. JPEG4 optionally accepts the f_alpha field. [To be verified]

These tags define an image saved using the JPEG compression scheme.

DefineBitsJPEG (V1.0) does not include the encoding tables which are defined in the unique JPEGTables tag instead. All the DefineBitsJPEG of an SWF file use the only JPEGTables tag. Yes... This means you need a tool that is capable of reusing the same tables over and over again to make sure that all your DefineBitsJPEGs work properly (or use it just once.)

The other tags incorporate their own version of the JPEG encoding tables.

The DefineBitsJPEG3 and DefineBitsJPEG4 support an alpha channel bit plane (8 bits.) ...

SWF Tag (swf_tag, swf_long_tag)

SWF Structure Info
Tag Flash Version: 
1
SWF Structure: 
struct swf_tag {
	unsigned short		f_tag_and_size;
	f_tag = f_tag_and_size >> 6;
	f_tag_data_size = f_tag_and_size & 0x3F;
	if(f_tag_data_size == 63) {
		unsigned long	f_tag_data_real_size;
	}
	else {
		f_tag_data_real_size = f_tag_data_size;
	}
};

struct swf_long_tag { /* i.e. the last 6 bits of f_tag_and_size = 0x3F */
	unsigned short		f_tag_and_size;
	f_tag = f_tag_and_size >> 6;
	unsigned long	f_tag_data_real_size;
};

The tag and size are saved in a 16 bits little endian unsigned integer. The tag is always aligned to a byte (not a bit). The size is defined in the lower 6 bits. And the short value is in a little endian format as expected by the declaration. If the size is 63 (0x3F), then another 4 bytes are read for the size. This is used for really large tags such as fonts with many characters, audio, video, or images.

File Header

Tag Info
Tag Number: 
-1
Tag Type: 
Format
Tag Flash Version: 
1
Brief Description: 

Although it isn't a tag per say, we consider the file header as being a tag because it represents a block in the flash file. Since version 8, it can be complemented by the FileAttributes tag.

Tag Structure: 
struct swf_header {1
	unsigned char		f_magic[3];	/* 'FWS' or 'CWS' */
	unsigned char		f_version;
	unsigned long		f_file_length;
}

struct swf_header_movie {2
	swf_rect		f_frame_size;
	unsigned short fixed	f_frame_rate;
	unsigned short		f_frame_count;
};
  • 1. This part is never compressed
  • 2. Although considered part of the header, this part is compressed in the 'CWS' format.

The file header is found at the very beginning of the file. It should be used to determine whether a file is an SWF file or not. Also, it contains information about the frame size, the speed at which is should be played and the version (determining the tags and actions possibly used in the file).

The f_magic[3] array is defined as the characters: 'FWS' (it is going backward probably because it was supposed to be read in a little endian as a long word). A movie can be compressed when the version is set to 6 or more. In this case, the magic characters are: 'CWS'.

The f_version ...

SWF Tags

The following table is a list of all the SWF tags defined in this documentation.

This table presents the tags sorted using their number. There are tables available to find tags by name, by version of Flash releases, and by type.

IDsort icon Tag Name Type Comments Version
-1. File Header Format

Although it isn't a tag per say, we consider the file header as being a tag because it represents a block in the flash file. Since version 8, it can be complemented by the FileAttributes tag.

1
End Format

Mark the end of the file or a Sprite. It can't appear anywhere else but the end of the file or a Sprite.

1
1. ShowFrame Display

Display the current display list and pauses for 1 frame as defined in the file header.

1
2. DefineShape Define

Define a simple geometric shape.

1
3. FreeCharacter Define

Release a character which won't be used in this movie anymore.

1
4. PlaceObject Display

Place the specified object in the current display list.

1
5. RemoveObject Display

Remove the specified object at the specified depth.

1
6. DefineBitsJPEG Define

Define a JPEG bit stream.

1
7. DefineButton Define

Define an action button.

1
8. JPEGTables Define

Define the tables used to compress/decompress all the SWF 1.0 JPEG images (See also DefineBitsJPEG.)

1
9. SetBackgroundColor Display

Change the background color. Defaults to white if unspecified.

1
10. DefineFont Define

List shapes corresponding to glyphs.

1
11. DefineText Define

Defines a text of characters displayed using a font. This definition doesn't support any transparency.

1
12. DoAction Action

Actions to perform at the time the next show frame is reached and before the result is being displayed. It can duplicate sprites, start/stop movie clips, etc.

All the actions within a frame are executed sequentially in the order they are defined.

Important: many actions are not supported in Adobe Flash version 1. Please, see the reference of actions below in order to know which actions can be used with which version of Adobe Flash.

1
13. DefineFontInfo Define

Information about a previously defined font. Includes the font style, a map and the font name.

1
14. DefineSound Define

Declare a sound effect. This tag defines sound samples that can later be played back using either a StartSound or a DefineButtonSound. Note that the same DefineSound block can actually include multiple sound files and only part of the entire sound can be played back as required.

2
15. StartSound Display

Start playing the referenced sound on the next ShowFrame.

2
15. StopSound Display

Start playing the referenced sound on the next ShowFrame.

2
17. DefineButtonSound Define

Defines how to play a sound effect for when an event occurs on the referenced button.

2
18. SoundStreamHead Define

Declare a sound effect which will be interleaved with a movie data so as to be loaded over a network connection while being played.

2
19. SoundStreamBlock Define

A block of sound data (i.e. audio samples.) The size of this block of data is defined in the previous SoundStreamHead tag. It is used to download sound samples on a per frame basis instead of all at once.

2
20. DefineBitsLossless Define

A bitmap compressed using ZLIB (similar to the PNG format).

2
21. DefineBitsJPEG2 Define

Defines a complete JPEG image (includes the bit stream and the tables all in one thus enabling multiple tables to be used within the same SWF file).

Since Flash version 10, the data can also be set to a valid PNG or GIF89a. There is no need to specify the image format in the tag since the data describing the image includes the necessary information.

2
22. DefineShape2 Define

Brief Description: 

Define a simple geometric shape.

2
23. DefineButtonCxform Define

Setup a color transformation for a button.

2
24. Protect Define

Disable edition capabilities of the given SWF file. Though this doesn't need to be enforced by an SWF editor, it marks the file as being copyrighted in a way.

WARNING: this tag is only valid in Flash V2.x, V3.x, and V4.x, use the EnableDebugger instead in V5.x and EnableDebugger2 in V6.x and newer movies.

2
25. PathsArePostscript Define

The shape paths are defined as in postscript?

3
26. PlaceObject2 Define

Place, replace, remove an object in the current display list.

3
28. RemoveObject2 Display

Remove the object at the specified level. This tag should be used in movies version 3 and over since it compressed better than the standard RemoveObject tag. Note that a PlaceObject2 can also be used for this task.

3
29. SyncFrame Display

Tag used to synchronize the animation with the hardware.

3
31. FreeAll Define

Probably an action that would be used to clear everything out.

3
32. DefineShape3 Define

Brief Description: 

Define a simple geometric shape.

3
33. DefineText2 Define

Defines a text of characters displayed using a font. Transparency is supported with this tag.

3
34. DefineButton2 Define

Define an action button. Includes a color transformation. 

3
35. DefineBitsJPEG3 Define

Defines a complete JPEG image, i.e. a verbatim JPEG image file. The JPEG image is then followed by an alpha channel. Note that the alpha channel uses the Z-lib compression. Since Flash 10, the supported image formats are JPEG, PNG and GIF89a.

3
36. DefineBitsLossless2 Define

Defines an RGBA bitmap compressed using ZLIB (similar to the PNG format).

3
37. DefineEditText Define

An edit text enables the end users to enter text in a Flash window.

4
38. DefineVideo Define

Apparently, Macromedia did have a first attempt in supporting video on their platform. It looks, however, as if they reconsidered at that point in time.

4
39. DefineSprite Define

Declares an animated character. This is similar to a shape with a display list so the character can be changing on its own over time.

3
40. NameCharacter Define

Define the name of an object (for buttons, bitmaps, sprites and sounds.)

3
41. ProductInfo Define

This tag defines information about the product used to generate the animation. The product identifier should be unique among all the products. The info includes a product identifier, a product edition, a major and minor version, a build number and the date of compilation. All of this information is all about the generator, not the output movie.

3
42. DefineTextFormat Define

Another tag that Flash ended up not using.

1
43. FrameLabel Define

Names a frame or anchor. This frame can later be referenced using this name.

3
45. SoundStreamHead2 Define

Declare a sound effect which will be interleaved with a movie data so as to be loaded over a network connection while being played.

3
46. DefineMorphShape Define

This is similar to a sprite with a simple morphing between two shapes.

3
47. GenerateFrame Define

This may have been something similar to a New in an action script and thus was removed later.

3
48. DefineFont2 Define

Define a list of glyphs using shapes and other font metric information.

3
49. GeneratorCommand Define

Gives some information about the tool which generated this SWF file and its version.

3
50. DefineCommandObject Define

?

5
51. CharacterSet Define

It looks like this would have been some sort of DefineSprite extension... did not make it out either.

5
52. ExternalFont Define

It looks like accessing a system font was going to be another tag, but instead Macromedia made use of a flag in the existing DefineFont2 tag.

5
56. Export Define

Exports a list of definitions declared external so they can be used in other movies. You can in this way create one or more movies to hold a collection of objects to be reused by other movies without having to duplicate these in each movie. A single export is enough for an entire movie (and you should have just one).

5
57. Import Define

Imports a list of definitions that are to be loaded from another movie. You can retrieve objects that were exported in the specified movie. You can have as many import as you like, though you should really only have one per referenced movie.

5
58. EnableDebugger Format

The data of this tag is an MD5 password like the EnableDebugger2 tag. When it exists and you know the password, you will be given the right to debug the movie with Flash V5.x and higher.

WARNING: this tag is only valid in Flash V5.x, use the EnableDebugger2 instead in V6.x and newer movies and Protect in older movies (V2.x, V3.x, and V4.x).

5
59. DoInitAction Action

Actions to perform the first time the following Show Frame tag is reached. All the initialization actions are executed before any other actions. You have to specify a sprite to which the actions are applied to. Thus you don't need a set target action. When multiple initialization action blocks are within the same frame, they are executed one after another in the order they appear in that frame.

6
60. DefineVideoStream Define

Defines the necessary information for the player to display a video stream (i.e. size, codec, how to decode the data, etc.). Play the frames with VideoFrame tags.

6
61. VideoFrame Define

Show the specified video frame of a movie.

6
62. DefineFontInfo2 Define

Defines information about a font, like the DefineFontInfo tag plus a language reference. To force the use of a given language, this tag should be used in v6.x+ movies instead of the DefineFontInfo tag.

6
63. DebugID Define

This tag is used when debugging an SWF movie. It gives information about what debug file to load to match the SWF movie with the source. The identifier is a UUID.

6
64. EnableDebugger2 Format

The data of this tag is a 16 bits word followed by an MD5 password like the EnableDebugger tag. When it exists and you know the password, you will be given the right to debug the movie with Flash V6.x and over.

WARNING: this tag is only valid in Flash V6.x and over, use the EnableDebugger instead in V5.x and Protect in older movies (V2.x, V3.x, and V4.x).

6
65. ScriptLimits Define

Change limits used to ensure scripts do not use more resources than what you choose. In version 7, it supports a maximum recursive depth and a maximum amount of time scripts can be run for in seconds.

7
66. SetTabIndex Define

Define the order index so the player knows where to go next when the Tab key is pressed by the user.

7
69. FileAttributes Format

Since version 8, this tag is required and needs to be the very first tag in the movie. It is used as a way to better handle security within the Flash Player.

8
70. PlaceObject3 Display

Place an object in the display list. The object can include bitmap caching information, a blend mode and a set of filters.

8
71. Import2 Define

Imports a list of definitions from another movie. In version 8+, this tag replaces the original Import tag. You can retrieve objects which were exported in the specified movie. You can have as many import as you like, although you should really only have one per referenced movie.

8
72. DoABCDefine Action

New container tag for ActionScripts under SWF 9. Includes only actions. This tag is not defined in the official Flash documentation.

9
73. DefineFontAlignZones Define

Define advanced hints about a font glyphs to place them on a pixel boundary.

8
74. CSMTextSettings Define

Define whether CSM text should be used in a previous DefineText, DefineText2 or DefineEditText.

8
75. DefineFont3 Define

Define a list of glyphs using shapes and other font metric information.

8
76. SymbolClass Action

Instantiate objects from a set of classes.

9
77. Metadata Format

This tag includes XML code describing the movie. The format is RDF compliant to the XMP as defined on W3C.

8
78. DefineScalingGrid Define

Define scale factors for a window, a button, or other similar objects.

8
82. DoABC Action

New container tag for ActionScripts under SWF 9. Includes an identifier, a name and actions.

9
83. DefineShape4 Define

Declare a shape which supports new line caps, scaling and fill options.

8
84. DefineMorphShape2 Define

Declare a morphing shape with attributes supported by version 8+.

8
86. DefineSceneAndFrameData Define

Define raw data for scenes and frames.

9
87. DefineBinaryData Define

Defines a buffer of any size with any binary user data.

9
88. DefineFontName Define

Define the legal font name and copyright.

9
90. DefineBitsJPEG4 Define

Defines a complete JPEG (the image formats supported are JPEG, PNG and GIF89a) and includes a deblocking filter parameter. The JPEG image is then followed by an alpha channel. Note that the alpha channel uses the Z-lib compression.

10

About SWF

Brief History

At the very beginning, a company created the SWF format to generate small vector animations on the Internet called Shockwave Flash (hence the name of the format, SWF.) It also included images. This company was bought by Macromedia around 1997 (if I recall properly). This is when Flash v3 was created. Since then, Macromedia created a new version about once a year up to version 8. At that time (in 2005/2006), Macromedia sealed a deal with Adobe which wanted to use the SWF format in their PDF files.

Today (May 1st, 2008), the SWF format is available for free to all.

There was ...

Notes about Copyrights

SSWF™ name

The name SSWF™ is used by Made to Order Software to reference its SWF library. You are welcome to use this name in reference the SSWF library if you use it in your own software.

SWF Format

Please, note that there is no restriction in using this document. However, the SWF format copyright holders are Macromedia and Adobe. There may be limits in what you can do using this format. If you are not sure, I suggest you contact a knowledgeable copyright and Software attorney who can help you decide what you can do with the SWF format.

SSWF Authors

This document was written by Alexis Wilke. Different people have helped in fixing mistakes in the different structures defined here. Their names appear in the Appendix B — History of the SSWF reference.

SWF File Format Reference

The Flash File Format Explained

The SWF file format is used for Flash. SWF stands for Shockwave Format1, the very first company that created the Flash animation format later bought by Macromedia and now owned by Adobe.

The following book is an attempt in describing the binary file ...

  • 1. There are many people who found other names for the acronym such as Shockwave Flash, Shock Wave File, Small Web Format, Serious Wow Factor, and SWIFF. History of man kind is confronted with the same problems, unfortunately. And no... it really has nothing to do with the Swiss Wrestling Federation!