
Added by roScripts on August-25-2007, 2:46 pm
/*
************************************************************
Developed by R.Arul Kumaran [arul@shockwave-india.com] *
for more code keep visiting [www.shockwave-india.com/blog] *
************************************************************
*/
/*
| Object.copyProperties(toObj, PropertyStr, exclude?)
|
| toObj: Object to which properties to be copied
|
| propertyStr: list of properties to be included or excluded in
| "#property1#property2#property3#" format
|
| exclude: boolean specifies whether to exclude or include the properties
| mentioned in the propertyStr
*/
Object.prototype.copyProperties = function(toObj, propertyStr, exclude) {
if (this instanceof Array) {
for (var i = 0; i<this.length; i++) {
if (typeof (this[i]) == "object") {
toObj[i] = this[i] instanceof Array ? new Array() : new Object();
this[i].copyProperties(toObj[i], propertyStr, exclude);
} else {
toObj[i] = this[i];
}
}
} else {
for (var i in this) {
var index = propertyStr.indexOf("#"+i+"#");
if ((exclude && index == -1) || (!exclude && index != -1)) {
if (typeof (this[i]) == "object") {
toObj[i] = this[i] instanceof Array ? [] : {};
this[i].copyProperties(toObj[i], propertyStr, exclude);
} else {
toObj[i] = this[i];
}
}
}
}
}
ASSetPropFlags(Object.prototype, ["copyProperties"], 1);
/*
Example:-
// creating a generic object with some properties we need
myObj = {align:"left", color:0xFF0000, name:"arul", gender:"male"};
//creating a textformat object
myTextFormat = new TextFormat();
//method 1
myObj.copyProperties(myTextFormat, "#align#color#")
//myTextFormat now has align and color properties
//method 2
myObj.copyProperties(myTextFormat, "#name#gender#",true)
//myTextFormat now has all the properties copied except name and gender
*/
Added by roScripts on March-26-2008, 5:14 pm
Added by roScripts on March-26-2008, 5:13 pm
Added by roScripts on March-26-2008, 5:09 pm
Added by roScripts on March-26-2008, 5:08 pm
Added by roScripts on March-26-2008, 5:07 pm