The way I see it all the the item renderer is there only for display purposes. 
All the sock retrievals goes in to the provider, rrrrrr I mean the model which 
feeds the list provider. If you use binding the list will automatically display 
that changes. Now here-s something we do to avoid object creation... We use an 
array for fast retieval on the element and an array collection for binding ...
In your case that would be translated into something like a stocks collection 
manager which has an stocksArray : Array and stocksAC: ArrayColection. U use an 
id to identify the element in the collection and that is unique ... when a 
stock comes in if it's new u add it, otherwise just update an existing one ... 
The rest is the magic of binding ...

    public function addStock(stock : Stock) : void
        {
            if (this._stocksArray.id + "_"] == null)
            {
                this._stocksArray[stock.id + "_"] = stock;
                this._stocksArrayCollection.addItem(stock);
            }
            else 
            {
                Stock(this._stocksArray[stock.id + "_"]).update(stock);
            }
        }

the update function shoul be in the Stock class and jus update stock 
properties...

HTH,
Claudiu

Probably you have an answer by now form other peeps but I just started readimng 
tehm emails ....




________________________________
From: flexrookie <[email protected]>
To: [email protected]
Sent: Sunday, March 1, 2009 3:58:30 AM
Subject: [flexcoders] updating an item renderer


hi list, first post...

i have an architectural question about datatproviders and
itemrenderers that i'll pose with a canonical example.

suppose i have an array of StockInfo objects that is populated by a
3rd party library. each StockInfo object dispatches UPDATE events when
a stock price changes. i want to render the prices in HorizontalList
with a custom renderer.

here's the general application shell:

============ ========= ====
<?xml version="1.0" encoding="utf- 8"?>
<mx:Application xmlns:mx="http://www.adobe. com/2006/ mxml"
layout="absolute"
applicationComplete ="applicationCom pleteListener( event)">
<mx:Script>
<![CDATA[
import mx.controls. HorizontalList;
import mx.events.FlexEvent ;
import mx.core.ClassFactor y;

protected var list:HorizontalList ;
protected var stocks:Array;

protected function applicationComplete Listener (e:FlexEvent) :void {
// Stock data (hardcoded for the example)
stocks = [new StockInfo()] ;

// UI
list = new HorizontalList( );
list.width = 400;
list.height = 100;
list.itemRenderer = new ClassFactory( StockInfoRendere r);
addChild(list) ;
} 
]]>
</mx:Script>
</mx:Application>
============ ========= ====

i need to wire the stocks array to the list. of course, given that i
already have an array of StockInfo objects, it's tempting to make an
ArrayCollection wrapper that gives direct access to the StockInfo
objects. e.g.,

provider = new ArrayCollection( );
provider.addItem( {stockInfo: someStockInfoObj ect});

then the StockInfoRenderer could register for UPDATE events and redraw
when the event occurs. but i'm hesitant about that approach. if i went
that route,

1) within the StockInfoRenderer, where would i register for the UPDATE
event? in commitProperties( )?
2) within the StockInfoRenderer, where would i *remove* the UPDATE
listener?
3) given that renderers are reused, are there issues with synching, or
with stranded listeners causing memory build-up?

more generally, what's the right way to wire my list to the stocks
array? it feels like i might be forced to handle UPDATE for each
StockInfo object, and write a 'price' variable into a data provider.
e.g., 

provider.getItemAt( i).price = value;
provider.itemUpdate d(provider. getItemAt( i), "price");

seems a shame, given that i already have an array of StockInfo
objects. the above two lines presuppose that i'm going to hunt for the
item index every time a stock price changes. : (

another general question, do i even need the itemUpdate() call, or is
that part automated?

thanks for any advice!

flexrookie


   


      

Reply via email to