2 Replies Latest reply on Jul 13, 2010 3:00 AM by Fabian89

    ArrayCollections -> removeAll

    Fabian89

      Hello,

       

      I have declared an ArrayCollection:

       

      [Bindable]
                     private var LCArray:ArrayCollection = new ArrayCollection ([{
                          Time: 0, 
                          Voltage: 0, 
                          Flux: 0, 
                          Memristance: 0,
                          Charge: 0,
                          Width: 0
                     }]);
      

       

      and every time a function (which I have declared afterwards) is called, I would like to empty the array collection. To do so, I first used LCArray.removeAll(); but I am getting the following error:

       

      RangeError: Index '200' specified is out of bounds.
           at mx.collections::ListCollectionView/removeItemAt()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:753]
           at Memristor/generateArray2()[C:\Users\Fabian\Adobe Flash Builder 4\Memristor\src\Memristor.mxml:57]
           at Memristor/checkData()[C:\Users\Fabian\Adobe Flash Builder 4\Memristor\src\Memristor.mxml:90]
           at Memristor/___Memristor_Button1_click()[C:\Users\Fabian\Adobe Flash Builder 4\Memristor\src\Memristor.mxml:284]
      
       
      
      
      

       

      I have since read that removeAll() is very inefficient for large ArrayCollections, and it might be better to use:

       

      LCArray = null;
      LCArray = new ArrayCollection();
      

       

      I have tried this, and running a for loop eliminating each element individually (LCArray.removeItemAt(i) where i = 0 to LCArray.length). I get the same problem as before.

       

      Any ideas on how to solve this problem?

       

      Thanks