Made to Order Software Corporation Logo

body

DoInitAction

Tag Info
Tag Number: 
59
Tag Type: 
Action
Tag Flash Version: 
6
Brief Description: 

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.

Tag Structure: 

Tag Structure: 
struct swf_doaction {
	swf_tag			f_tag;		/* 12 and 59 */
	if(f_tag == DoInitAction) {
		unsigned short	f_action_sprite;
	}
	swf_action		f_action_record[variable];
};

The DoAction tag will be used to execute a set of actions in place. Usually, actions are used on buttons to add interactivity to the SWF movies. In version 1 you had only one dynamic branch (WaitForFrame). In version 4 you can test many different things such as a position, angle or sound track cursor position. Since version 5, SWF has a complete scripting language supporting string and arithmetic operations.

The DoInitAction tag is used when a sprite needs to be initialized. These actions are carried on the sprite only once. These are outside of the given sprite and will reference the sprite so all the actions are automatically applied to the sprite without you having to do a SetTarget.

The following describes the data in the DoAction and DoInitAction tags:

The f_action_sprite is a reference (identifier) to the sprite which will be initialized with the given actions.

The f_action_record is an array of actions terminated by an End action.

The following is a list of all the actions supported by SWF format. The Version tells you what version of Flash player you need in order to use the given action (otherwise it is likely to be ignored or worse, make the player crash). Note that Macromedia defines all the actions as being part of version 3 and over. Thus, any action mark as being available in earlier versions (version 1 or 2) may in fact not be (though the DoAction and DefineButton tags were part of version 1!!!)

The Length (Stacked) column specifies the length of the data following the property (only with the action ID is 0x80 to 0xFF) and what will be pushed onto the stack. All the expressions work as in polish notation: push the parameters, then execute an order that uses the data from the stack. The actions that do not push anything on the stack have nothing written between parenthesis.

The Data & Operation column specifies what data follows the action and what the operation is. If there is no data and no operation, then n.a. is used. The data will be described as a list of fields as in the other structures described in this document. The operations will be written as closely as possible to a C like operation (though strings are managed in a much different way than C!) Anything which is popped from the stack will be given a letter and a digit. The digit represents the count or position and the letter the type of the data (a count of 1 represents the first pop, a count of 2 represents the second pop, etc.) The following column (Comments) will explain how the operation uses the data when appropriate.

The data types used are as follow:

    Short Type
    a any type
    b boolean
    f foat
    i integer
    n(1) numeric (integer or float)
    o(2) object (as in C++)
    s string
    t array or table of values
    v variable - pushes multiple values on the stack

    (1) when I don't know whether an integer or a float should be specified I will use 'n' as well. This should be correct most of the time anyway.
    (2) an object reference can be obtained by evaluating the name of that object; thus GetVariable("carrot") will return a reference to the carrot object.

The following lists all the actions by name. Those that have the comment (typed) operates taking the type of its arguments in account as defined in ECMA-262 Section 11.6.1 (arithmetic), 11.8.5 (comparison), 11.9.3 (equality) which you can certainly find somewhere on the Internet. Version 3 is available here: ECMA-262 V3.0. The functions which are not typed will behave by (1) trying to transform parameters in values, then perform the operation with numbers only or (2) when strings cannot be transformed in values, perform a string operation.

EnableDebugger

Tag Info
Tag Number: 
58
Tag Type: 
Format
Tag Flash Version: 
5
Brief Description: 

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).

Tag Structure: 

Tag Structure: 
struct swf_protect {
	swf_tag			f_tag;		/* 24, 58 or 64  */
	if(version >= 5) {
		if(tag == ProtectDebug2) {
			unsigned short	f_reserved;1
		}
		/* the password is optional when tag == Protect */
		string		f_md5_password;
	}
};
  • 1. f_reserved must be set to zero.

See Also: 

The protection tag is totally useless. The SWF format is an open format, otherwise how would you have so many players and tools to work with SWF movies? Thus, you can pretend to protect your movies, but anyone with a simple binary editor can transform the tag and make it another which has no such effect. Also, swf_dump and some other tools (such as flasm) can read your movie anyway.

For the sake of defining what you have in each tag, there are the protection tags fully described.

According to Macromedia, you can find some free implementation of the MD5 algorithm by Poul-Henning Kamp in FreeBSD in the file src/lib/libcrypt/crypt-md5.c. For your convenience, there is an implementation of that MD5 sum in the SSWF library.

IMPORTANT

Version 2, 3, 4 must use Protect.

Version 5 must use EnableDebugger.

Version 6 and over must use EnableDebugger2.

DefineMorphShape

Tag Info
Tag Number: 
46
Tag Type: 
Define
Tag Flash Version: 
3
Brief Description: 

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

Tag Structure: 

Tag Structure: 
struct swf_defineshape {
	swf_tag				f_tag;		/* 2, 22, 32, 46, 83, or 84 */
	unsigned short			f_shape_id;
	swf_rect			f_rect;
	is_morph = f_tag == DefineMorphShape || f_tag == DefineMorphShape2;
	has_strokes = f_tag == DefineShape4 || f_tag == DefineMorphShape2;
	if(is_morph) {
		swf_rect			f_rect_morph;
	}
	if(has_strokes) {
		swf_rect			f_stroke_rect;
		if(is_morph) {
			swf_rect			f_stroke_rect_morph;
		}
		unsigned			f_define_shape_reserved : 6;
		unsigned			f_define_shape_non_scaling_strokes : 1;
		unsigned			f_define_shape_scaling_strokes : 1;
	}
	if(is_morph) {
		unsigned long			f_offset_morph;
		swf_morph_shape_with_style	f_morph_shape_with_style;
	}
	else {
		swf_shape_with_style		f_shape_with_style;
	}
};

These are probably the most important tags in this reference. They are used to define a shape using Bezier curves and lines with different styles. The DefineShape of V1.0 is usually enough unless you need a large number of styles or you want to specify colors with an alpha channel (RGBA).

The DefineMorphShape and DefineMorphShape2 can be used to render an intermediate shape between two defined shapes. All the points and control points of both shapes must match. This is because the rendering of the morphing shapes is just an interpolation between both shapes points and control points positions. The interpolation is a very simple linear function (note however that you still can use a non-linear transformation effect in the end.) Most of the parameters in a shape definition are doubled when this tag is used. It otherwise looks very similar.

The f_stroke_rect and f_stroke_rect_morph rectangles define the boundaries around their respective shapes without the line strokes (excluding the thickness of the line.)

The f_define_shape_non_scaling_strokes flag should be set to 1 if at least one of the line strokes always stays the same while morphing.

The f_define_shape_scaling_strokes flag should be set to 1 if at least one of the line strokes is changing while morphing.

The f_offset_morph 32 bits value gives the offset from after that value to the start of the second shape (the shape to morph to.) In other words, this value can be used to skip the styles and the first shape at once.

SoundStreamHead2

Tag Info
Tag Number: 
45
Tag Type: 
Define
Tag Flash Version: 
3
Brief Description: 

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

Tag Structure: 

Tag Structure: 
struct swf_soundstreamhead {
	swf_tag			f_tag;		/* 18 or 45 */
	unsigned		f_compression : 4;
	unsigned		f_sound_rate : 2;
	unsigned		f_sound_size : 1;
	unsigned		f_sound_stereo : 1;
	unsigned		f_reserved : 4;
	unsigned		f_playback_rate : 2;
	unsigned		f_playback_size : 1;
	unsigned		f_playback_stereo : 1;
	unsigned short		f_sample_size;
	if(f_compression == 2) {
		signed short	f_latency_seek;
	}
};

The SoundStreamHead[2] tags define a sound effect which is to be loaded with a set of SoundStreamBlock tags. It defines the sound once and for all.

Streaming sound has a strong side effect when playing a movie: it will force a synchronization between the images and the audio. Thus some images may be dropped if the drawing isn't fast enough.

Streaming sound effects should be either used in the main movie or in a sprite which needs a sound track properly synchronized to the sprite animation. Otherwise, it is much better to use the DefineSound and StartSound tags.

It seems (though it isn't documented) that using a SoundStreamHead tag by itself (without any sound blocks) is taken as a hint of how to play all the other sounds in an animation (see the f_playback_rate)

Important note: there can be only one streaming sound per movie clip including the main movie. If you need multiple sound effects or music to be played back, these will have to be merged at the time you create the movie in a single sound which will then be played back as a single sound track.

Some of the fields in the SoundStreamHead tag can't have all the possible values when defined in an older version of SWF. What follows describes each field in more details.

The f_playback_rate and f_sound_rate define the rate at which the data should be played and the exact rate of the data found in the SWF file.

	rate = 5512.5 * 2 ** f_playback_rate
	rate = 5512.5 * 2 ** f_sound_rate

The f_playback_size and f_sound_size define the number of bits found in the data (0 for 8 bits and 1 for 16 bits.) Note that with a SoundStreamHead tag (18) only 16 bits data are allowed (both are always set to 1). If the compression mode isn't Raw or Uncompressed then the f_sound_size must be set to 1.

The f_playback_stereo and f_sound_stereo define whether the sound should be played on both speakers and whether the data includes both channels.

The f_compression entry defines the compression mode. The list of sound compression modes can be found with the DefineSound tag. Note that with a SoundStreamHead tag (18) only the ADPCM compression is accepted. All the compression modes are accepted in a SoundStreamHead2 tag (45).

The f_sample_size represents the average number of samples per frame. It is used to ensure a proper synchronization. Note that there can be more (and even less in MP3) samples within a given frame.

The f_latency_seek is usually zero. It exists only when the MP3 compression mode is used. It defines the number of samples to skip at the beginning of the very first frame (I'm not totally sure what this is to tell you the truth... I'll tell you more once I know more).

DefineBitsLossless2

Tag Info
Tag Number: 
36
Tag Type: 
Define
Tag Flash Version: 
3
Brief Description: 

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

Tag Structure: 

Tag Structure: 
struct swf_definebitslossless {
	swf_long_tag		f_tag;		/* 20 or 36 */
	unsigned short		f_image_id;
	unsigned char		f_format;	/* 3, 4 or 5 */
	unsigned short		f_width;
	unsigned short		f_height;
	if(f_format == 3) {
		unsigned char	f_colormap_count;
		if(f_tag == DefineBitsLossless) {
			swf_rgb		f_colormap[f_colormap_count];
		}
		else {
			swf_rgba	f_colormap[f_colormap_count];
		}
		unsigned char	f_indices[((f_width + 3) & -4) * f_height];
	}
	else {
		if(f_tag == DefineBitsLossless) {
			swf_xrgb	f_bitmap[f_width * f_height];
		}
		else {
			swf_argb	f_bitmap[f_width * f_height];
		}
	}
};

These tags declares a loss-less image bitmap. It has a small header followed by an optional colormap and the bitmap data. When we have a colormap, the bitmap data is an array of indices in the colormap aligned to 4 bytes on a per row basis.

There are three supported formats:

Format
No.
(bits)
Color Format Comments
Without
Alpha
With
Alpha
3
(8 bits(1))
RGB RGBA Uses a colormap with up to 256 entries of 24 or 32 bits colors.
4
(16 bits(1))
RGB555 RGB555 There is no alpha available in this format. The data is saved in big endian (it is NOT a U16 like some documentations say it is). The colors looks like this (most significant bit first): 0RRRRRGGGGGBBBBB. You should certainly always use the DefineBitsLossless tag for this format.
5
(32 bits)
XRGB ARGB Uses a strange order for the components. Most probably because the alpha was added later and thus inserted in place of the X to keep some backward compatibility with older versions.

(1) the data must be 32 bits aligned (4 bytes) on a per row basis. In 8 bits, you may have to add up to three bytes at the end of each row ( 4 - width & 3 when width & 3 is not zero.). In 16 bits, you need to add two bytes at the end of each row when the width of the image is odd.

The f_colormap, f_indices and f_bitmap are all compressed with the ZLIB scheme.

WATCH OUT: the f_colormap and f_indices are compressed as one large block.

WARNING: These tags require you to save the swf_tag in long format (i.e. f_tag_and_size & 0x3F == 0x3F even if the size is smaller than 63.)

WARNING: An image cannot always be scaled more than 64×. Trying to enlarge it more may result in a rectangle of one color. The 64× is cumulative. So a sprite of an image × 3 inside another sprite × 10 inside another sprite × 4 results in scaling of 120 and this is likely to break the image. This seems to be true mainly when there is a rotation or skew.

DefineBitsJPEG3

Tag Info
Tag Number: 
35
Tag Type: 
Define
Tag Flash Version: 
3
Brief Description: 

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.

Tag Structure: 

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.) This alpha channel is compressed using the ZLIB scheme as defined with the DefineBitsLossless image formats and appears at the end.

With Flash 10, DefineBitsJPEG4 was introduced to support a deblocking filter parameter. This parameter should be set to a value between 0.0 and 1.0 (0x0000 and 0x0100--so really a value from 0 to 256 inclusive.)

WARNING: These tags require you to save the swf_tag in long format (i.e. f_tag_and_size & 0x3F == 0x3F even if the size is smaller.)

f_encoding should include 0xFF 0xDB and 0xFF 0xC4 entries.

The f_image_data buffer should include the 0xFF 0xE0, 0xFF 0xC0 and 0xFF 0xDA.

Since Flash 10 the f_encoding and f_image_data fields defined in the DefineBitsJPEG2, DefineBitsJPEG3 and DefineBitsJPEG4 tags, are viewed as one single large buffer and thus it can be a verbatim JPEG, PNG or GIF89a file.

When the buffer represents a JPEG, it starts with 0xFF 0xD8 and ends with 0xFF 0xD9.

When the buffer represents a PNG, it starts with 0x89 0x50 'P' 0x4E 'N' 0x47 'G' 0x0D '\r' 0x0A '\n' 0x1A '^Z' 0x0A '\n'.

When the buffer represents a GIF89a, it starts with 0x47 'G' 0x49 'I' 0x46 'F' 0x38 '8' 0x39 '9' 0x61 'a'.

WARNING: Up to Flash 7, both buffers (f_encoding and f_image_data) need to start with a 0xFF 0xD8 (SOI) and end with 0xFF 0xD9 (EOI). Since Flash 8, this practice should not be used anymore.

The f_alpha buffer is compressed with ZLIB as defined in the DefineBitsLossless tag (this is similar to the PNG format). WARNING: this field only works with JPEG data. A PNG or GIF89a cannot make use of this field (but they can make use of their own alpha channel.)

Note:   The Flash 10 documentation says that the f_alpha field is optional. This means you can save a JPEG in a DefineBitsJPEG4 without the Alpha Channel but still make use of the deblocking filter parameter. Before Flash 10, use DefineBitsJPEG2 instead (safer).

The DefineBitsJPEG tag may fail if it includes any encoding tables. These tables shall be defined within the JPEGTables instead.

Note that the Adobe SWF player better enforces the correctness of these tags since version 8. Some older movies may not work properly with Flash Player 8+.

DefineText2

Tag Info
Tag Number: 
33
Tag Type: 
Define
Tag Flash Version: 
3
Brief Description: 

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

Tag Structure: 

Tag Structure: 
struct swf_definetext {
	swf_tag			f_tag;		/* 11 or 33 */
	unsigned short		f_text_id;
	swf_rect		f_rect;
	swf_matrix		f_matrix;
	unsigned char		f_glyph_bits;
	unsigned char		f_advance_bits;
	swf_text_record		f_text_record;
};

Define an object of text so the SWF player can draw a string. The only difference between the DefineText and DefineText2 tags is that the latter supports RGBA colors. This can be seen in one of the swf_text_record structures.

Since version 8 it is possible to define extraneous parameters when defining a CSMTextSettings tag referencing a DefineText or DefineText2.

SWF ARGB (swf_argb)

SWF Structure Info
Tag Flash Version: 
1
SWF Structure: 
struct swf_argb {
	unsigned char		f_alpha;1
	unsigned char		f_red;
	unsigned char		f_green;
	unsigned char		f_blue;
};
  • 1. 0 represents a fully transparent color, 255 represents a solid color.

The color components can be set to any value from 0 (no intensity) to maximum intensity (255).1

It is important to note that even fully transparent pixels may not have their red, green, blue components set to 0. This is useful if you want to add a value to the alpha channel using one of the color transformation matrices. In that case, using all 0's would generate a black color.

  • 1. For some PNG images, the red, green and blue colors may need to be multiplied by their alpha channel value before saved. Use the following formula to compute the proper values:

       f_red = orginal red * f_alpha / 255

This format was added to be mostly compatible with the old PNG format (XRGB).

DefineShape3

Tag Info
Tag Number: 
32
Tag Type: 
Define
Tag Flash Version: 
3
Brief Description: 

Brief Description: 

Define a simple geometric shape.

Tag Structure: 

Tag Structure: 
struct swf_defineshape {
	swf_tag				f_tag;		/* 2, 22, 32, 46, 83, or 84 */
	unsigned short			f_shape_id;
	swf_rect			f_rect;
	is_morph = f_tag == DefineMorphShape || f_tag == DefineMorphShape2;
	has_strokes = f_tag == DefineShape4 || f_tag == DefineMorphShape2;
	if(is_morph) {
		swf_rect			f_rect_morph;
	}
	if(has_strokes) {
		swf_rect			f_stroke_rect;
		if(is_morph) {
			swf_rect			f_stroke_rect_morph;
		}
		unsigned			f_define_shape_reserved : 6;
		unsigned			f_define_shape_non_scaling_strokes : 1;
		unsigned			f_define_shape_scaling_strokes : 1;
	}
	if(is_morph) {
		unsigned long			f_offset_morph;
		swf_morph_shape_with_style	f_morph_shape_with_style;
	}
	else {
		swf_shape_with_style		f_shape_with_style;
	}
};

These are probably the most important tags in this reference. They are used to define a shape using Bezier curves and lines with different styles. The DefineShape of V1.0 is usually enough unless you need a large number of styles or you want to specify colors with an alpha channel (RGBA).

The DefineMorphShape and DefineMorphShape2 can be used to render an intermediate shape between two defined shapes. All the points and control points of both shapes must match. This is because the rendering of the morphing shapes is just an interpolation between both shapes points and control points positions. The interpolation is a very simple linear function (note however that you still can use a non-linear transformation effect in the end.) Most of the parameters in a shape definition are doubled when this tag is used. It otherwise looks very similar.

The f_stroke_rect and f_stroke_rect_morph rectangles define the boundaries around their respective shapes without the line strokes (excluding the thickness of the line.)

The f_define_shape_non_scaling_strokes flag should be set to 1 if at least one of the line strokes always stays the same while morphing.

The f_define_shape_scaling_strokes flag should be set to 1 if at least one of the line strokes is changing while morphing.

The f_offset_morph 32 bits value gives the offset from after that value to the start of the second shape (the shape to morph to.) In other words, this value can be used to skip the styles and the first shape at once.

RemoveObject2

Tag Info
Tag Number: 
28
Tag Type: 
Display
Tag Flash Version: 
3
Brief Description: 

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.

Tag Structure: 

Tag Structure: 
struct swf_removeobject {
	swf_tag			f_tag;		/* 5 or 28 */
	if(f_tag == RemoveObject) {
		unsigned short		f_object_id_ref;
	}
	unsigned short		f_depth;
};

Remove the specified object from the display list. If the same object was placed multiple times at the specified depth1 only the last copy is removed. When only a depth is specified, the last object placed at that depth is removed from the list. Note that since version 3 it is possible to use the PlaceObject2 in order to replace an object at a given depth without having to remove it first.

  • 1. It is illegal, yet possible, to place more than one object at the same depth.