Depending on how you will use this, you might consider extending ArrayCollection and adding getItemByKey support.
I have not done this, but would probably try maintaining an associative array in the extended AC. Come to think of it one of our component gurus might already have done such a thing, or know why not to try! Do a search. Tracy ________________________________ From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Tim Hoff Sent: Tuesday, June 03, 2008 9:42 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: replacing items in an arraycollection? If you're rolling your own, that's the way. -TH --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , "blc187" <[EMAIL PROTECTED]> wrote: > > I have an ArrayCollection of objects that I am receiving updates on. > On update, I get the updated item as an argument and I need to > replace the old item in the list. > Right now I am cycling through the ArrayCollection until i find the > id of the item and returning the index, then replacing the item at > that index. > Any thoughts on a better way to do this? > > > public var itemCollection:ArrayCollection; > > public function onUpdateReceived(newItem:Object):void { > findIndex(newItem); > if(index > -1) > itemCollection.setItemAt(newItem, index); > } > > public function findIndex(newItem:Object):Number { > > for each(var itemInCollection:Object in itemCollection){ > if(itemInCollection.id == newItem.id) return > itemCollection.getItemIndex(itemInCollection); > } > > return -1; > } >