I’ve implemented this in com.emoten.core.data.JKDataObject in EmotenCore.swc
The [Transient] metadata is very important. ( keeps it from tying to infinitely clone itself )
I looked elsewhere and it seems that no-one has noticed that the [RemoteClass] metadata is required to reconstruct the class from its AMF-serialized state.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | [Transient] /** * Creates a Clone of this class. * <p> * In order for your returned class to be typed correctly you must put the following * above "public class" * * <code> * [RemoteClass(alias="com.emoten.core.data.JKDataObject")] * </code> * * Replacing "com.emoten.core.data.JKDataObject" with your class's FQN. * * @return A new copy of your class. */ public function clone():* { var ba:ByteArray = new ByteArray(); ba.writeObject( this ); ba.position = 0; return ba.readObject(); } |
1 2 | [RemoteClass(alias="com.emoten.core.data.JKDataObject")] public class JKDataObject extends JKObject implements Cloneable |
UPDATE: Krilnon over at Kirupa made a good point I forgot to cover. The restrictions are that of the AMF specification. You cannot pass things like DisplayObjects and you cannot have required constructor arguments. If you don’t have those, your cool. The clone() functionality is only really intended for data models.
http://www.kirupa.com/forum/showpost.php?p=2489122&postcount=597