Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deep Cloning in Actionscript

Tags:

actionscript

What is the best method to deep clone objects in actionscript?

like image 989
Cookie Avatar asked Apr 27 '11 07:04

Cookie


People also ask

What does deep clone do?

A shallow copy of an object references the original. So any changes made to the original object will be reflected in the copy. A deep copy is a copy of all elements of the original object. Changes made to the original object will not be reflected in the copy.

How do you create a deep clone of an object?

Copy an Object With Object.assign() was the most popular way to deep copy an object. Object. assign() will copy everything into the new object, including any functions. Mutating the copied object also doesn't affect the original object.

What is deep clone C#?

Deep Copy: It is a process of creating a new object and then copying the fields of the current object to the newly created object to make a complete copy of the internal reference types. If the specified field is a value type, then a bit-by-bit copy of the field will be performed.

What is deep copy in VB net?

Deep copy is creating a new object and then copying the nonstatic fields of the current object to the new object. If a field is a value type --> a bit-by-bit copy of the field is performed. If a field is a reference type --> a new copy of the referred object is performed.


1 Answers

The best method to do this is by using the ByteArray with the method writeObject. Like this:

function clone(source:Object):* {
    var copier:ByteArray = new ByteArray();
    copier.writeObject(source);
    copier.position = 0;
    return(copier.readObject());
}

More information about this, here: http://www.kirupa.com/forum/showpost.php?p=1897368&postcount;=77

like image 57
rzetterberg Avatar answered Sep 22 '22 23:09

rzetterberg