Flex: the clone function duplicates my data

I have weird behavior using ObjectUtil.copy () and ByteArray.writeObject / readObject ().
I clone an ArrayCollection, and at some point I get two identical instances 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 do not understand what I did wrong. Is there something missing? It does not play for all ArrayCollection. It has been working fine for a while. Is this an ObjectUtil.copy () function error?

+3
source share
1 answer

If you need an array clown that will contain references to the original instances of the array collection, can't you just clone the original array?

eg.

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

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

Source: https://habr.com/ru/post/1731389/


All Articles