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

 

senocular.com ActionScript Library

copyTo.as

Name: Function.prototype.copyTo() - (MX) copies a function to other objects
Author: senocular: www.senocular.com
Date: 1899-12-31T00:17:17.200
Documentation:
Function COPYTO: copies this function into any set
of objects or movieclip making it availble for use there.
 
Arguments:
- objs: array of objects which the function is to be added
- name: name of the function in the objects its being copied to
 


Example:
clip1.onEnterFrame = function(){
	this._x++;
}
clip1.onMouseDown = function(){ // add clip1 enterframe to clip2 and clip3
	 bob.onEnterFrame.copyTo([clip2, clip3], "onEnterFrame");
}
 
Math.abs.copyTo([Array.prototype], "abs"); // add abs to array instances
myArray = []; 
trace(myArray.abs(-10)); // 10 

1
2
3
4
Function.prototype.copyTo = function(objs, name){
	var i, l = objs.length;
	for (i=0;i<l;i++) objs[i][name] = this;
}