Flash duplication of Object-Cloning library?

This is probably a very simple question, I just do not know how to do it.

I have an object that I want to duplicate and don’t know how to do it. Here is my attempt:

var myObj = new ObjectClass(); var duplicate = myObj; duplicate = null; myObj.function(); // Error: Null reference 

ObjectClass is very large, inherets and creates its own children, and I am sure that there may be several singleton classes there.

Is there a way to duplicate something easily?

Edit: It looks like I'm looking for “cloning” for which there is no AS3 function, and you, in turn, cannot clone personal data. Does anyone know a library or workaround for cloning a heap of personal data?

+4
source share
2 answers

I got this use function from some blog, I can’t remember where I can’t give a loan from. However, it does not work with bitmapdata. In any case, this is:

 public static function copy(o:Object):Object { var bytes:ByteArray = new ByteArray( ); bytes.writeObject( o ); bytes.position = 0; return bytes.readObject( ); } 

Using:
registerClassAlias ​​("com.tests.TestClass", TestClass); var testCopy: Testclass = TestClass (ObjectUtil.copy (test));

+4
source

You can use ObjectUtil.copy() (Flex library). But you are right that you do not support personal data. So this is a shot in the dark, but I wonder if you will serialize it in AMF using ByteArray.writeObject() if it copies personal data? Maybe worth a try.

+1
source

All Articles