Made to Order Software Corporation Logo

SWF

SWF Action (swf_action)

SWF Structure Info
Tag Flash Version: 
1
SWF Structure: 
/* basic definition of an action entry */
struct swf_action {
	unsigned char		f_action_id;
	f_action_has_length = (f_action_id & 0x80) != 0;
	if(f_action_has_length) {
		unsigned short		f_action_length;
		unsigned char		f_action_data[f_action_length];
	}
};

An action is defined with an identifier, and an optional size and data (pretty much like a tag).

Note that the optional size and data are defined only for actions with an identifier of 128 or more. The other identifiers are always defined by themselves. Actions without immediate data may still access data. In that case, the data is taken from the stack.

Please, see the action list for all the supported actions.

SWF Any Filter (swf_any_filter)

SWF Structure Info
Tag Flash Version: 
8
SWF Structure: 
/* the filter type */
struct swf_filter_type {
	unsigned char	f_type;
};

struct swf_filter_glow {
	swf_filter_type	f_type;		/* 0, 2, 3, 4 or 7 */
	if(f_type == GradientGlow || f_type == GradientBevel) {
		unsigned char		f_count;
	}
	else {
		f_count = 1;
	}
	swf_rgba		f_rgba[f_count];
	if(f_type == Bevel) {
		swf_rgba		f_highlight_rgba[f_count];
	}
	if(f_type == GradientGlow || f_type == GradientBevel) {
		unsigned char		f_position[f_count];
	}
	signed long fixed	f_blur_horizontal;
	signed long fixed	f_blur_vertical;
	if(f_type != Glow) {
		signed long fixed	f_radian_angle;
		signed long fixed	f_distance;
	}
	signed short fixed	f_strength;
	unsigned		f_inner_shadow : 1;
	unsigned		f_knock_out : 1;
	unsigned		f_composite_source : 1;
	if(f_type == Bevel) {
		unsigned		f_on_top : 1;
	}
	else {
		unsigned		f_reserved : 1;
	}
	if(f_type == GradientGlow || f_type == GradientBevel) {
		unsigned		f_passes : 4;
	}
	else {
		unsigned		f_reserved : 4;
	}
};

struct swf_filter_blur {
	swf_filter_type		f_type;	/* 1 */
	unsigned long fixed	f_blur_horizontal;
	unsigned long fixed	f_blur_vertical;
	unsigned		f_passes : 5;
	unsigned		f_reserved : 3;
};

struct swf_filter_convolution {
	swf_filter_type	f_type;		/* 5 */
	unsigned char	f_columns;
	unsigned char	f_rows;
	long float	f_divisor;
	long float	f_bias;
	long float	f_weights[f_columns × f_rows];
	swf_rgba	f_default_color;
	unsigned	f_reserved : 6;
	unsigned	f_clamp : 1;
	unsigned	f_preserve_alpha : 1;
};

struct swf_filter_colormatrix {
	swf_filter_type	f_type;		/* 6 */
	long float	f_matrix[20];
};

struct swf_any_filter {
	swf_filter_type			f_fitler_type;
	swf_filter_blur			f_filter_blur;
	swf_filter_colormatrix		f_filter_colormatrix;
	swf_filter_convolution		f_filter_convolution;
	swf_filter_glow			f_filter_glow;
};

A filter defines how to transform the objects it is attached to. The first byte is the filter type. The data following depend on the type. Because each filter is much different, they are defined in separate structures. You can attach a filter to an object using an ActionScript or the PlaceObject3 tag.

The following describes the different filters available since version 8.

...
Value Name Version
0 Drop Shadow 8

SWF Color Transform (swf_color_transform)

SWF Structure Info
Tag Flash Version: 
1
SWF Structure: 
struct swf_color_transform {
	char align;
	unsigned		f_color_has_add : 1;
	unsigned		f_color_has_mult : 1;
	unsigned		f_color_bits : 4;
	if(f_color_has_mult) {
		signed short fixed	f_color_red_mult : f_color_bits;
		signed short fixed	f_color_green_mult : f_color_bits;
		signed short fixed	f_color_blue_mult : f_color_bits;
		if(f_tag == PlaceObject2) {
			signed short fixed	f_color_alpha_mult : f_color_bits;
		}
	}
	if(f_color_has_add) {
		signed short fixed	f_color_red_add : f_color_bits;
		signed short fixed	f_color_green_add : f_color_bits;
		signed short fixed	f_color_blue_add : f_color_bits;
		if(f_tag == PlaceObject2) {
			signed short fixed	f_color_alpha_add : f_color_bits;
		}
	}
};

When the f_color_<component>_mult are not defined in the input file, use 1.0 by default. When the f_color_<component>_add are not defined in the input file, use 0.0 by default.

The factors are saved as 8.8 fixed values (divide by 256 to obtain a proper floating point value). Note that the values are limited to a signed 16 bits value. This allows for any value between -128.0 and +127.98828.

When the resulting color is defined, the multiplication is applied first as in:

	result-component = source-component * component-mult + component-add;

The result is then clamped between ...

SWF Gradient Record (swf_gradient_record)

SWF Structure Info
Tag Flash Version: 
3
SWF Structure: 
struct swf_gradient_record {
	if(f_tag == DefineMorphShape || f_tag == DefineMorphShape2) {
		unsigned char	f_position;
		swf_rgba	f_rgba;
		unsigned char	f_position_morph;
		swf_rgba	f_rgba_morph;
	}
	else if(f_tag == DefineShape3 || f_tag == DefineShape4) {
		unsigned char	f_position;
		swf_rgba	f_rgba;
	}
	else {
		unsigned char	f_position;
		swf_rgb		f_rgb;
	}
};

The first record position should be 0 and the last 255. The intermediate should use the corresponding value depending on their position in the gradient effect.

SWF Gradient (swf_gradient)

SWF Structure Info
Tag Flash Version: 
3
SWF Structure: 
struct swf_gradient {
	if(tag == DefineShape4) {
		unsigned		f_spread_mode : 2;
		unsigned		f_interpolation_mode : 2;
		unsigned		f_count : 4;
	}
	else {
		unsigned		f_pad : 4;
		unsigned		f_count : 4;
	}
	swf_gradient_record	f_gradient_record[f_count];
	/* f_type is defined in the swf_fill_style encompassing this gradient */
	if(f_type == 0x13) {
		signed short fixed	f_focal_point;
	}
};

This structure defines a gradient. This is a set of colors which are used to define an image with colors smoothly varying from one color to the next. The gradient can be radial (circular) or linear (rectangular).

The f_count field is limited depending on the tag used and the version of SWF as defined below:

SWF Text Entry (swf_text_entry)

SWF Structure Info
Tag Flash Version: 
1
SWF Structure: 
struct swf_text_entry {
	unsigned		f_glyph_index : f_glyph_bits;
	signed			f_advance : f_advance_bits;
};

The swf_text_entry structure defines a list of characters and the number of TWIPs to skip to go to the next character. Note that f_advance is a signed value. Thus you can write characters from right to left which is useful to write characters in languages such as Arabic in a native way. The number of bits used to define each field of this structure is defined in the DefineText or DefineText2 tags.

SWF Text Record (swf_text_record)

SWF Structure Info
Tag Flash Version: 
1
SWF Structure: 
struct swf_text_record_end {
	unsigned		f_end : 8;	/* all zeroes */
};

struct swf_text_record_setup {
	unsigned		f_type_setup : 1;	/* always one */
	unsigned		f_reserved : 3;
	unsigned		f_has_font : 1;
	unsigned		f_has_color : 1;
	unsigned		f_has_move_y : 1;
	unsigned		f_has_move_x : 1;
	if(f_has_font) {
		unsigned short		f_font_id_ref;
	}
	if(f_has_color) {
		if(tag == DefineText) {
			swf_rgb		f_color;
		}
		else {	/* if tag is DefineText2 */
			swf_rgba	f_color;
		}
	}
	if(f_has_move_x) {
		signed short		f_move_x;
	}
	if(f_has_move_y) {
		signed short		f_move_y;
	}
	if(f_has_font) {
		unsigned short		f_font_height;
	}
};

struct swf_text_record_glyphs {
	unsigned		f_type_glyph : 1;		/* always zero */
	unsigned		f_glyph_count : 7;		/* at least one */
	swf_text_entry		f_entry[f_glyph_count];
};

struct swf_text_record_string {
	unsigned		f_type_setup : 1;	/* always one */
	unsigned		f_reserved : 3;
	unsigned		f_has_font : 1;
	unsigned		f_has_color : 1;
	unsigned		f_has_move_y : 1;
	unsigned		f_has_move_x : 1;
	if(f_has_font) {
		unsigned short		f_font_id_ref;
	}
	if(f_has_color) {
		if(tag == DefineText) {
			swf_rgb		f_color;
		}
		else {	/* if tag is DefineText2 */
			swf_rgba	f_color;
		}
	}
	if(f_has_move_x) {
		signed short		f_move_x;
	}
	if(f_has_move_y) {
		signed short		f_move_y;
	}
	if(f_has_font) {
		unsigned short		f_font_height;
	}
	unsigned char		f_glyph_count;		/* at least one */
	swf_text_entry		f_entry[f_glyph_count];
};

union swf_text_record {
	unsigned		f_flags : 8;
	swf_text_record_end	f_end;
	if(version >= 7) {
		swf_text_record_string	f_string;
	}
	else {
		swf_text_record_setup	f_setup;
		swf_text_record_glyphs	f_glyphs;
	}
};

The swf_text_record structure is a union composed of a swf_text_record_setup definition followed by characters. Multiple records can follow each others. The list is ended with one byte set to 0.

WARNING: it seems that Macromedia didn't think about a file having two records of type glyph one after another (it makes their plugins crash); you will have to insert a setup record between each glyph record (the setup can be empty: i.e. add one byte equal to 0x80). The very first setup has to at least define the font.

NOTE: this has been corrected by Macromedia it now shows as one structure ...

SWF Matrix (swf_matrix)

SWF Structure Info
Tag Flash Version: 
1
SWF Structure: 
struct swf_matrix {
	char align;
	unsigned		f_has_scale : 1;
	if(f_has_scale) {
		unsigned	f_scale_bits : 5;
		signed fixed	f_scale_x : f_scale_bits;
		signed fixed	f_scale_y : f_scale_bits;
	}
	unsigned		f_has_rotate : 1;
	if(f_has_rotate) {
		unsigned	f_rotate_bits : 5;
		signed fixed	f_rotate_skew0 : f_rotate_bits;
		signed fixed	f_rotate_skew1 : f_rotate_bits;
	}
	unsigned		f_translate_bits : 5;
	signed			f_translate_x : f_rotate_bits;
	signed			f_translate_y : f_rotate_bits;
};

By default...

  • f_scale_x and f_scale_y are set to 1.0
  • f_rotate_skew0 and f_rotate_skew1 are set to 0.0
  • f_translate_x and f_translate_y must be specified. The translation can be set to (0, 0) to avoid any side effects.

Scale is a ratio. Rotate is an angle in radian. Translate is in TWIPs (1/20th of a pixel.)

SWF Line Style (swf_line_style)

SWF Structure Info
Tag Flash Version: 
1
SWF Structure: 
struct swf_line_style {
	if(f_tag == DefineMorphShape) {
		unsigned short twips	f_width;
		unsigned short twips	f_width_morph;
		swf_rgba		f_rgba;
		swf_rgba		f_rgba_morph;
	}
	else if(f_tag == DefineShape4 || f_tag == DefineMorphShape2) {
		unsigned short twips	f_width;
		if(f_tag == DefineMorphShape2) {
			unsigned short twips	f_width_morph;
		}
		unsigned		f_start_cap_style : 2;
		unsigned		f_join_style : 2;
		unsigned		f_has_fill : 1;
		unsigned		f_no_hscale : 1;
		unsigned		f_no_vscale : 1;
		unsigned		f_pixel_hinting : 1;
		unsigned		f_reserved : 5;
		unsigned		f_no_close : 1;
		unsigned		f_end_cap_style : 2;
		if(f_join_style == 2) {
			unsigned short fixed	f_miter_limit_factor;
		}
		if(f_has_fill) {
			swf_fill_style		f_fill_style;
		}
		else {
			swf_rgba		f_rgba;
			if(f_tag == DefineMorphShape2) {
				swf_rgba		f_rgba_morph;
			}
		}
	}
	else if(f_tag == DefineShape3) {
		unsigned short twips	f_width;
		swf_rgba		f_rgba;
	}
	else {
		unsigned short twips	f_width;
		swf_rgb				f_rgb;
	}
};

The width of the line is in TWIPS (1/20th of a pixel).

The f_start_cap_style and f_end_cap_style can be:

  • 0 - Round cap,
  • 1 - No cap,
  • 2 - Square cap.

Round is the default, the way line caps looked before version 8. No Cap means that nothing is added at the tip of the line. This means the line stops exactly where you say it should end. The Square Cap is like the No Cap, but it has the cap which is about Width / 2.

The f_join_style can be:

SWF Line Style Array (swf_line_style_array)

SWF Structure Info
Tag Flash Version: 
1
SWF Structure: 
struct swf_line_style_array {
	unsigned char		f_count;
	if(f_tag != DefineShape && f_count == 255) {
		unsigned short	f_real_count;
	}
	else {
		f_real_count = f_count;
	}
	swf_line_style		f_line_style[f_real_count];
};

The array of line styles starts with a counter. When DefineShape is used, the counter can be any value from 0 (no style) to 255. When DefineShape2 or DefineShape3 are used, the value 255 is reserved so you can declare more than 255 styles (up to 65535.)