tags:

views:

202

answers:

1

Hello,
I've some strange behavior using ObjectUtil.copy() and ByteArray.writeObject/readObject().
I clone an ArrayCollection and sometime the result is two identical instance of the class.

Example :

var item:Object = new Object();
item.name = "Hello World";

var listItem:ArrayCollection = new ArrayCollection();
listItem.push(item:Object );

var cloneList:ArrayCollection = ObjectUtil.copy(listItem);

trace(cloneList.length);    
// 2

I don't understand what I've done wrong. Is there something is missed ? It is not reproductible for all ArrayCollection. Some time, it works fine. Is it a bug of ObjectUtil.copy() function ?

A: 

If you need a clone of an array collection that will hold references to the original array collection's instances, can you not just clone the source array ?

e.g.

var listItem:ArrayCollection = new ArrayCollection();
listItem.push(item:Object );

var cloneList:ArrayCollection = new ArrayCollection(new Array().concat(listItem.source));
George Profenza