AS3 数组深度复制

 

//简单复制后,修改副本会修改原对象,深度复制后,修改副本不修改原对象

var arr:Array = new Array("A","B");
trace(arr);//A,B

var deepCopy:ByteArray = new ByteArray();
deepCopy.writeObject(arr);
deepCopy.position = 0;

var arr2:Array = deepCopy.readObject() as Array;
trace(arr2);//A,B

arr2[0] = "Z";
trace(arr);//A,B
trace(arr2);//Z,B

你可能感兴趣的:(数组,as3,深度复制)