views:

23

answers:

1

The situation is simple. I have a datagrid that gets its data from a webservice.

When data from the webservice is retrived it calls the following function:

private function onListReg():void
{
    arrRegOld = WSAutoreg.list.lastResult as ArrayCollection;
    arrReg = WSAutoreg.list.lastResult as ArrayCollection;

    dgReg.dataProvider = autoreglist;
}

dgReg is the Datagrid. the arr variables are ArrayCollections defined like so:

private var arrRegOld:ArrayCollection = new ArrayCollection;

[Bindable]
private var arrReg:ArrayCollection = new ArrayCollection;

The intent is when I hit a update button, it compares arrRegOld with arrReg and see if any values have changes. The problem is whenever I change values on the Datagrid it changes on both the dataProvider and on both ArrayCollections.

Does anyone know why is this happening? What should I do so that the binding applies only to one ArrayCollection?

Appreciate any tip. - Mike

+1  A: 

Your lists are sharing the same objects, if you modify the first element from arrReg you will see the modification also in arrRegOld - it is not related to binding. You need to clone the objects. You have several choices:

a) Implement a clone method for your objects (recommended) b) Use a generic method like this one:

            private function clone(source:Object):*             
            {               
                var array:ByteArray=new ByteArray();                    
                array.writeObject(source);                  
                array.position=0;                   
                return(array.readObject());             
            }

and call arrRegOld = clone (arrReg); after arrReg = WSAutoreg.list.lastResult as ArrayCollection;

Cornel Creanga
Worked like a charm. Thanks alot.
MikeDaSpike