4 Replies Latest reply on Oct 23, 2008 5:57 AM by m_hartnett

    Creating 2 dataproviders from one remote object

      Hello,
      I have created a remote object that populates an arrayCollection to be used as a dataprovider for a pulldown menu item. In one instance I want to append data to the dataProvider to show an additional item in the list and in the other dataProvider I just want the data returned from the Remote call. The problem is that when I add the additional item to the list it is also reflected in the second arrayCollection. How can I use one remote call to populate 2 separate arraycollections and not have changes made to one of the collections reflected in the other?
        • 1. Re: Creating 2 dataproviders from one remote object
          sharat87
          As far as i understood your question, you are using the same instance of arraycollection as dataprovider for both the components. You should clone the arraycollection and then use it as the dataprovider for the other component.
          The attached code should help you cloning objects...

          Hope this helps :)
          1 person found this helpful
          • 2. Creating 2 dataproviders from one remote object
            Not quite... What I have is one datacall the populates two different arrayCollections that are dataproviders. In one of the arrayCollections I'm adding an additional element (i.e. Show All), but in the other array collection I don't want the additional option to be visible. When I add the additional element to the first arrayCollection it modifies the second arrayCollection .
            Here's my code (short hand):

            [Bindable] array1:ArrayCollection = new ArrayCollection();
            [Bindable] array2:ArrayCollection = new ArrayCollection();

            private function getData():void{
            ----Code to get data from server here
            ----call to function to handle result();
            }
            private function handleResult(e:ResultEvent):void{
            array1 = e.ResultEvent as ArrayCollection;
            array1.addItemAt("Show All", 0);
            array2 = e.ResultEvent as ArrayCollection;
            }
            When I add the item to array1 it is also reflected in array2 and I don't want this as these ACs are used to populate pulldown menus. Hope this helps to clarify...
            • 3. Re: Creating 2 dataproviders from one remote object
              sharat87 Level 1
              If this is the code you are using, then it indeed is the problem of single instance.
              in the function handleResult(), you assign array1 to e.result. Here, no new instance is created. its the same arraycollection bothe the identifiers 'array1' and 'e.result' point to. and later in the third line, array2 will also point to the same arraycollection instance which has the extra element.

              Hope this helps
              1 person found this helpful
              • 4. Re: Creating 2 dataproviders from one remote object
                m_hartnett Level 3
                Try this.

                private function handleResult(e:ResultEvent):void{

                //copy the returned result using the ObjectUtil object. This will create a copy of what has been returned
                array1 = ObjectUtil.copy(e.ResultEvent) as ArrayCollection;
                array1.addItemAt("Show All", 0);

                //Use what was returned unmodified as the second collection
                array2 = e.ResultEvent as ArrayCollection;
                }