1 Reply Latest reply on Jul 23, 2010 5:49 PM by UbuntuPenguin

    Efficient way to populate ArrayCollection from remote method call

    Yury Bel

      Hi,

      I'm looking for an efficient and correct tehnique to populate ArrayCollection in remote method result event.

      For instance, I have:

       

      [Bindable] private var dp:ArrayCollection;

      <mx:DataGrid dataProvider="{dp}" />

      <mx:RemoteObject id="ro" destination="dest" >

           <mx:method name="getData" result="{getDataResult(event);}" />

           ...

      </mx:RemoteObject>

       

      private function getDataResult(e:ResultEvent):void {

      // And my question goes here!!!

      }

       

      Well, usually getDataResult looks like:

      private function getDataResult(e:ResultEvent):void {

           dp = event.result as ArrayCollection;

      }

       

      But it seems there is a problem if somebody set the listener this way:

      dp.addEventListener(CollectionEvent.COLLECTION_CHANGE, function(event:CollectionEvent):void {});

      because it is removed.

       

      Well, I tried the following:

      private function getDataResult(e:ResultEvent):void {

           dp.removeAll();

           dp.addAll(event.result as ArrayCollection);

      }

      And there is no problem with listeners.

       

      So, what tehnique (efficient and correct) should I use?

       

      Thanks