hi folks,
how is it possible to clone an object, rather than creating a
reference to an object ?
For example: I have to Objects, ObjA and ObjB; when i call ObjA = ObjB
and ObjB changes, ObjA also changes.
In Flash itself there is a way using the function below, in flex this
doesnt work, or maybe I´m putting it in the wrong place (currently
in
the Application Script tag)
Object.prototype.clone = function() {
if (this instanceof Array) {
var to = [];
for (var i = 0; i<this.length; i++) {
to[i] = (typeof (this[i]) == "object") ?
this[i].clone() : this[i];
}
} else if (this instanceof XML || this instanceof MovieClip) {
// can't clone this so return null
var to = null;
trace("Warning! Object.clone can not be used on
MovieClip or XML objects");
} else {
var to = {};
for (var i in this) {
to[i] = (typeof (this[i]) == "object") ?
this[i].clone() : this[i];
}
}
return to;
};
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/