Made to Order Software Corporation Logo

matrix

DefineScalingGrid

Tag Info
Tag Number: 
78
Tag Type: 
Define
Tag Flash Version: 
8
Brief Description: 

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

Tag Structure: 
struct swf_definescalinggrid {
	swf_tag				f_tag;		/* 78 */
	unsigned short			f_button_id_ref;
	swf_rect			f_rect;
};

This definition is used so the scaling factors applied on an object affects only the center of the object fully. The borders are only affected in one direction and the corners are not scaled (note, restrictions apply, see below.) This is quite useful to draw a scalable button or window.


Fig 1 — Sample button being scaled with a scaling grid

Appendix B — History of the SSWF reference

Dec 2, 2009

Moved the monolithic documentation to a multi-page hierarchical document that includes everything we had before plus many links, many terms attached to all pages (tags, English words.) And revision of most of the text for better English and clarification in some places.

Strengthen the formatting with CCK fields so all declarations look alike.

Broken up the actions from one large table to a set of pages.

Dec 14, 2008

Started work on the Load() feature of the SSWF library. This helped fixing several small mistakes in the documentation.

May 18, 2008

Fixed the ...

Appendix A — The geometry in SWF — Images

When appropriate, images can also be included in SWF files. All the images can be full color and also have an alpha channel.

Appendix A — The geometry in SWF — Edges

Edges are used to define a shape vector based and also coordinates where images need to be drawn. The edges are always coordinates from where ever your last point was to where ever you want the next point to be (a little like a turtle in LOGO).

Appendix A — The geometry in SWF — Matrix

The coordinates are often transformed with the use of a matrix. The matrix is similar to a transformation matrix in Postscript. It includes a set of scaling factors, rotation angles and translations.

When only the scaling factors are used (no rotation) then these are ratios as one would expect. If a rotation is also applied, then the scaling ratios will be affected accordingly.

SWF Button (swf_button)

SWF Structure Info
Tag Flash Version: 
1
SWF Structure: 
struct swf_button {
	char align;
	unsigned		f_button_reserved : 2;
	if(version >= 8) {
		unsigned		f_button_blend_mode : 1;
		unsigned		f_button_filter_list : 1;
	}
	else {
		unsigned		f_button_reserved : 2;
	}
	unsigned		f_button_state_hit_test : 1;
	unsigned		f_button_state_down : 1;
	unsigned		f_button_state_over : 1;
	unsigned		f_button_state_up : 1;
	if(any f_button_state_... != 0) {
		unsigned short		f_button_id_ref;
		unsigned short		f_button_layer;
		swf_matrix		f_matrix;
		if(f_tag == DefineButton2) {
			swf_color_transform		f_color_transform;
		}
		if(f_button_filter_list) {
			unsigned char		f_filter_count;
			swf_any_filter		f_filter;
		}
		if(f_button_blend_mode) {
			unsigned char		f_blend_mode;
		}
	}
};

A button structure defines a state and a corresponding shape reference. The shape will be affected by the specified matrix whenever used.

There are many acceptable combinations. The object which is referenced is drawn when its state matches the current state of the button. If only the f_button_state_hit_test is set, then the shape is always displayed.

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

PlaceObject2

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

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

Tag Structure: 
struct swf_placeobject2 {	/* and swf_placeobject3 */
	swf_tag			f_tag;		/* 26 or 70 */
	/* NOTE: the following flags can be read as one or two bytes also */
	if(version >= 8) {
		unsigned	f_place_reserved : 5;
		unsigned	f_place_bitmap_caching : 1;
		unsigned	f_place_blend_mode : 1;
		unsigned	f_place_filters : 1;
	}
	if(version >= 5) {
		unsigned	f_place_has_actions : 1;
	}
	else {
		unsigned	f_place_reserved : 1;
	}
	unsigned		f_place_has_clipping_depth : 1;
	unsigned		f_place_has_name : 1;
	unsigned		f_place_has_morph_position : 1;
	unsigned		f_place_has_color_transform : 1;
	unsigned		f_place_has_matrix : 1;
	unsigned		f_place_has_id_ref : 1;
	unsigned		f_place_has_move : 1;
	unsigned short		f_depth;
	if(f_place_has_id_ref) {
		unsigned short		f_object_id_ref;
	}
	if(f_place_has_matrix) {
		swf_matrix		f_matrix;
	}
	if(f_place_has_color_transform) {
		swf_color_transform	f_color_transform;
	}
	if(f_place_has_morph_position) {
		unsigned short		f_morph_position;
	}
	if(f_place_has_name) {
		string			f_name;1
	}
	if(f_place_has_clipping_depth) {
		unsigned short		f_clipping_depth;
	}
	/* 3 next entries since v8.0 */
	if(f_place_filters) {
		unsigned char		f_filter_count;
		swf_any_filter		f_filter;
	}
	if(f_place_blend_mode) {
		unsigned char		f_blend_mode;
	}
	if(f_place_bitmap_caching) {
		/* WARNING: this is not defined in the Macromedia documentation
		 * it may be that it was part of the blend mode whenever the person
		 * who defined this byte was testing (I copied that from somewhere else!).
		 */
		unsigned char		f_bitmap_caching;
	}
	/* since v5.0 */
	if(f_place_has_actions) {
		unsigned short		f_reserved;
		if(version >= 6) {
			unsigned long	f_all_flags;
		}
		else {
			unsigned short	f_all_flags;
		}
		swf_event		f_event[<variable>];
		if(version >= 6) {
			unsigned long	f_end;	/* always zero */
		}
		else {
			unsigned short	f_end;	/* always zero */
		}
	}
};
  • 1. Assuming that this PlaceObject2 references a DefineSprite, this name becomes the name of this instance of the sprite. This feature enables you to place the same DefineSprite multiple times in your display list each time using a different name.

This tag will be used to specify where and how to place an object in the next frame. The PlaceObject is much different and is presented separately.

The f_depth field is used to indicate at which depth the character is inserted in the current frame. There can be only one object per depth value (thus a maximum of 65536 objects can appear on a single frame).

The f_place_has_move and f_place_has_id_ref flags are used to indicate what to do at the given depth. The following table presents what happens depending on the current value.

f_place_has_move ...