3 Replies Latest reply on Nov 27, 2009 5:07 AM by JabbyPandaUA

    Duplicates when binding ArrayCollection to List



      I'm working on a flex application.

      There is a DataManger object that loads some XML data and store it in an ArrayCollection by doing something like that (code is simplified) :


      private var _xmlLocations:XMLListCollection;
      private var _countryList:ArrayCollection;
      _xmlLocations = new XMLListCollection(data..location);


      Then the DataManager send back the ArrayCollection to a component with a list using the Source setter.


      <mx:ArrayCollection id="arrayData" />
      <mx:List id="listMenu" dataProvider="{arrayData}">...</mx:List>
      public function set Source(data:ArrayCollection):void{
           arrayData.source = data.source;


      When I look at my ArrayCollection in the debugger, it first look like this :




      But after the binding to the List, the ArrayCollection arrayData has every entry duplicated...





      I'm probably doing something wrong... but what?

      Thanks for any lighting or advices

        • 1. Re: Duplicates when binding ArrayCollection to List
          paul.williams Level 4

          Are you sure that the 'addAll' call isn't being called twice? Try calling removeAll() on the ArrayCollection before you fill it.

          • 2. Re: Duplicates when binding ArrayCollection to List
            julien.63 Level 1

            Thanks for the reply

            It was not on the addAll(), but still I was indeed adding the items twice...

            Sorry for that

            • 3. Re: Duplicates when binding ArrayCollection to List
              JabbyPandaUA Level 3

              I cannot confirm your issue, I've created simple test MXML application  to validate it


              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
                          import mx.collections.ArrayCollection;
                          protected var initArr : Array = new Array(1, 2, 3);            
                          protected var initCollection : ArrayCollection = new ArrayCollection(initArr);
                          protected var dataCollection : ArrayCollection = new ArrayCollection();
                          public function set source(data:ArrayCollection):void {
                              dataCollection.source = data.source;
                          private function onCreationComplete() : void {
                              source = initCollection;   
                  <mx:List dataProvider="{dataCollection}"/>