Got something that does this, it's almost done. I'll post it online
somewhere soon and post a link on the list.

It's a helper class rather than an extension of ArrayCollection though, coz
that's more useful to me.

-J

On Thu, Jun 5, 2008 at 3:00 AM, Tracy Spratt <[EMAIL PROTECTED]> wrote:

>    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 <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;
> > }
> >
>
>  
>



-- 
"Therefore, send not to know For whom the bell tolls. It tolls for thee."

:: Josh 'G-Funk' McDonald
:: 0437 221 380 :: [EMAIL PROTECTED]

Reply via email to