6 Replies Latest reply on Oct 18, 2010 3:29 PM by Flex harUI

    ArrayCollection removeItem function


      Why doesn't ArrayCollection have a removeItem function?  I'm aware of ArrayCollection.removeItemAt(ArrayCollection.getItemIndex(item)); which I write all the time.  Why isn't there a convenience function to do this for us?

        • 1. Re: ArrayCollection removeItem function
          Flex harUI Adobe Employee

          Feel free to file an enhancement request.  I thought that most folks would

          be working from the selectedIndex or selectedIndices of a view of the

          ArrayCollection and wouldn't need it.

          1 person found this helpful
          • 3. Re: ArrayCollection removeItem function
            Devtron Level 3



            I wish the Array object had a better remove function as well.

            • 4. Re: ArrayCollection removeItem function
              Flex harUI Adobe Employee

              Can you add a scenario or two of why you need to do that but you don't have

              other index information available (like selectedIndex and/or


              • 5. Re: ArrayCollection removeItem function
                tehxike1 Level 1

                Notification Manager:


                I have a notification manager that displays warning/info messages to the user and keeps track of visible messages with an ArrayCollection.  When the user clicks on one of the messages, the manager closes that window and removes it from the collection.  From the click event, I have event.target, the item I want to remove from my view and from the ArrayCollection.  If the container exclusively held my dialogs, this wouldn't be a problem since the index of the message would be the same as the index in the ArrayCollection, but this isn't the case.



                Preference Manager:


                A preference manager (singleton) has an ArrayCollection of preferences that are fetched from the server and written back.  A view may request a single one of these preferences from the manager, which it can then manipulate or even choose to delete.  When it requests that the item be deleted, it has no concept of the location of this preference with relation to other preferences:


                public function deletePrefObject(pref:DataObject):void


                     if (prefs.contains(pref))







                Simpler case- subtraction


                var a:String = "a";

                var b:String = "b";

                var c:String = "c";

                var ac1:ArrayCollection = new ArrayCollection([a,b,c]);

                var ac2:ArrayCollection = new ArrayCollection ([b,c]);

                for each (var s:String in ac2)


                     if (ac1.contains(s))






                I'd prefer


                for each (var s:String in ac2)






                If it's a problem to have it gracefully fail when asking it to remove an item it doesn't contain, I'd still be really happy if I just no longer had to do removeItemAt(getItemIndex(.  I agree with Devtron that Array could benefit from this as well.  I also wish I didn't have to do Array.indexOf(item) != -1 - .contains( is so much cleaner.

                • 6. Re: ArrayCollection removeItem function
                  Flex harUI Adobe Employee

                  Add them to the bug please.  Keep in mind that getItemIndex does a linear

                  search.  It often better to cache the index, and even track it as other

                  inserts/deletes happen.