Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

senocular.com ActionScript Library

match.as

Name: match() - make a mc's visual properties match the properties of another
Author: senocular: www.senocular.com
Date: 1899-12-31T00:04:49.700
Documentation:
MovieClip MATCH: copies common visual properties (or properties
you specify) from one movieclip to 'this' movieclip
 
Arguments:
- mc: the movieclip to obtain the properties from
- props: (optional) any number of further arguments to specifically limit the properties copied.
If passed, only those passed (passed as strings) will be matched. Default: function's prop list.
 
Note:
- any non existant properties will be created and copied in the new movieclip
- _xscale and _yscale are favored over _height and _width in this example for the default
copying of properties.  This means if the sizes of the two clips are originally different,
they will not be sized to meet each other when matched, just have the same scale values.
- the default property list is not set in stone, feel free to change it ;)
 
Tip:
- you can pass an object in as the mc, as long as the properties contained are the same as
the movieclips, they will be carried over.

Example:
// Matches this clips position, scale, rotation and visibility to
// the clip called funky_mc in _root
onClipEvent(enterFrame){
	this.match(_root.funky_mc);
}

// Matches only this clips position to
// the clip called funky_mc in _root
onClipEvent(enterFrame){
	this.match(_root.funky_mc, "_x", "_y");
}

1
2
3
4
5
6
7
8
MovieClip.prototype.match = function(mc, props){
	var p, L = (props = arguments).length;
	if (L == 1) L = (props = [null, "_alpha","_visible","_rotation","_xscale","_yscale","_x","_y"]).length;
	while(--L){
		p = props[L];
		this[p] = mc[p];
	}
}