We've addressed this on flexcoders a few times before in the past.
 
You simply use ByteArray to clone an object or array.
 
var array:Array = [1, 2, 3];
var ba:ByteArray = new ByteArray();
ba.writeObject(array);
ba.position = 0;
var cloned:Array = ba.readObject() as Array;
 
You always use writeObject/readObject no matter what type you a writing.
These are the only two methods that use AMF to serialize/deserialize the
AS3 type.
 
Note that if you want to clone a strongly typed objects then you must
have registered a class alias for the type (or if you're using Flex to
compile your application you can use the [RemoteClass(alias="...")]
metadata).
 
package something
{
 
[RemoteClass(alias="something.Foo")]
public class Foo
{
    public function Foo()
    {
    }
}
}
 
 
import something.Foo;
 
var foo:Foo = new Foo();
var ba:ByteArray = new ByteArray();
ba.writeObject(foo);
ba.position = 0;
var clonedFoo:Foo = ba.readObject() as Foo;
 

Reply via email to