If you have control over the entire class hierarchy, I recommend implementing an interface clone()in each class. This is tiring, but will pay off as complexity increases.
(Excuse me if the syntax is a bit off, it has been a while)
public interface ICloneable {
function clone() : Object;
}
For each class, we implement the method ...
public class MyClass1 implements ICloneable {
...
public function clone() : Object {
var copy:MyClass1 = new MyClass1();
return copy;
}
}
To create a copy of an object, just call the function clone().
var copy:MyClass1 = original.clone();
As a note, both Java and .NET seem to have adopted methods cloneon their base classes Object. I do not know a similar method for the ActionScript class Object.
source
share