4 Replies Latest reply on Feb 20, 2009 11:25 AM by VarioPegged

    Filter arrayCollection based on items in another array?

    kmdguy Level 1
      I have an Array which holds some values: array1 = ["361,364"]

      These are id references which can frequently change.

      I have an arrayCollection that holds a bunch of records. I have experience writing code to do simple filtering of my arrayCollection using the filterFunction and a simple piece of criteria.

      I'm trying to come up with a loop for filtering my arrayCollection to look at the number of item in array1, and then filter my arrayCollection leaving only the entries that match the id numbers found in array1.

      I'm trying to use a "for...each" loop but I can't quite get the result I need...

      Sample:

      public var matchingID:int:

      private function filterArray():void
      {
      for each (var i:int in array1)
      {
      matchingID = i;
      arrayCollection.filterFunction = checkIDs;
      }
      arrayCollection.refresh();
      }

      private function checkIDs(item:Object):Boolean
      {
      if (item.id == matchingID)
      {
      return true;
      }
      else
      {
      return false;
      }
      }


      When I run this code I only end up with an arrayCollection consisting of only one entry, which is the last one. My brain is frozen trying to figure this one out. The values and amount of values will vary in array1 so I'm looking for a filtering loop for arrayCollection that will work no matter how many values are in array1.

      Any creative ideas?