My question is quite simple actually. I’m working with a remote object, that calls a service, and when I do the following:
Variable1 = remoteObject.serviceCalled.lastresult; (both are an ArrayCollection)
Variable2 = remoteObject.serviceCalled.lastresult; (both are an ArrayCollection)
And after that I modify Variable2, then the data in Variable1 gets modified as well, and I can’t understand why this keeps happening, and I can’t get to solve this issue. Even more, when I do:
And I modify variable 2, variable 1 also gets modified. Can someone help me solve this problem please?
Non-scalar values are passed by reference, so both variable1 and variable2
have a reference to the same ArrayCollection, not distinct copies.
Alex, thanks for your help. Can you tell me how can I have a different copies of the variable3 (when it's a NonScalar variable) in my variable1 and variable2?
To make a new ArrayCollection from an old one, do:
NewArrayCollection = new ArrayCollection(oldArrayCollection.source).
Note that any changes to the items they share will still be reflected in the
other after a refresh.
To make a truly distinct copy, you will need to make copies of each item in
the source and a new array of those copies.