4 Replies Latest reply on Nov 12, 2007 11:19 PM by Santanu Karar

    ArrayCollection getting Interlinked!!

    Santanu Karar Level 1
      I'm calling some data by httpServices in result which i'm gettin a XML and then i'm parsing it to a arrayCollection. I'm building 2 arraycollection with the datas. Now the problem is whenver i'm filtering any of them, the another also has the filtered effect!! I am feeling very helpless where I'm not filtering and I dont want to be filtered another arraycollection, bt the effect of the first ArrayCollection's filter function, the second one also get effected!!

      Please help!.. i need to stop this really urgently!

      Help!

      ASB
        • 1. Re: ArrayCollection getting Interlinked!!
          Gregory Lafrance Level 6
          Please simplify your code and post it here.
          • 2. ArrayCollection getting Interlinked!!
            Santanu Karar Level 1
            I'm using an remoteObject to call serverside list by which I'm building 2 different ArrayCollection. I'm giving the same code which I'm using in the result event of this remoteObject. You can see the source is an arrayCollection by which I'm building 2 more arrayCollection and in turn they're getting interlinked!

            -------------------------------------------------------------------
            Following is my resultEventHandler code:
            -----------------------------------------------------------------

            private function appHandler(event:ResultEvent):void { // this event.result actually retuns me an arrayCollection..

            appointmentsAC = new ArrayCollection();
            historyAppAC = new ArrayCollection();

            appointmentsAC = event.result as ArrayCollection;
            historyAppAC = event.result as ArrayCollection;

            trace("APPACLength >> "+appointmentsAC.length + " HISAPPACLength >> "+historyAppAC.length) // return both length 91

            appointmentsAC.filterFunction = doFilterAC;
            appointmentsAC.refresh();
            function doFilterAC(item: Object):Boolean {
            if (item.staffID == 67) return true;
            return false;
            }

            trace("APPACLength >> "+appointmentsAC.length + " HISAPPACLength >> "+historyAppAC.length) // returns both length 16!

            }
            ------------------------------------------------------

            In above code I've made 2 different arrayCollection by the list value i've got from event.result. Now in first trace, I've found both the arrayCollection's length is say, 91 records. Then I'm deploying a small filter function to one of the arrayCollection which filtered that arrayCollection to the length of 16.
            But when I'm tracing the both arrayCollection's length after the filter function happen, it returns the both of the arrayCollection's length is 16!! I've found that regardless of the use of the filter function to that specific arrayCollection, it also affects the other!

            Somehow they're getting referenced internally by other as I'm making both the arrayCollection from one event.result's list value! How do I stop this interlinking!
            • 3. Re: ArrayCollection getting Interlinked!!
              ntsiii Level 3
              This does not create two different ArrayCollections:
              appointmentsAC = event.result as ArrayCollection;
              historyAppAC = event.result as ArrayCollection;

              It creates two variables pointing at the same data.

              You will need to copy the data. The easiest way is to use XML.copy(), before you start creating the ArrayCollections.

              Tracy
              • 4. Re: ArrayCollection getting Interlinked!!
                Santanu Karar Level 1
                Hi, thanks.

                Though XML.copy() sounds like copying a XML file but I only getting here an ArrayCollection as event.result not any XML collection. In that scenario, does XML.copy() also works with this..?

                Anyway, I've also understood what you've just mentioned, two variables pointing at the same data. They are actually getting referenced with same. So, I've copied the values to another varaible by flex's deepCoping methods, and it works for me!

                But surely, would like to know whether XML.copy() will work with coming arrayCollection.


                Thanks.

                ASB