1 person found this helpful
Do you have a model of some kind ? If you don't I would have something like this
public class StockQuote extends EventDispatcher implements IUID
public var currentPrice:Number;
pubilc var previousPrice:Number;
In your itemrenderer I would do something like this.
override public function set data( value:Object ):void
super.data = value;
if( value != null )
var stockQuote:StockQuote = value as StockQuote;
if( stockQuote.currentPrice > stockQuote.previousPrice )
//run function to make background green
else if( stockQuote.currentPrice < stockQuote.previousPrice )
//run function to make background red
Don't put a custom property on the label because whether or not the price has changed belongs more in the model. That way, it doesn't matter how the prices and renderers are used/reused, the data used to calculate what color it should be stays in sync with itself. You may have to add a listener to the stock quote and do some other stuff to get it to work correctly on price changes.
Thank you for your answer Ubuntu, where would be the correct place to set the previous price? Im trying to set it in the creationComplete method for itemRenderer but it still seems to mismatch the different values from other renderers. For example if i have 2 cells in one column, lets say 0 and 7. If i increment both by one and then Alert out the previous and current values of stockQuote i get the following.
- oldquote: 0 new quote: 8
- oldquote: 7 new quote: 1
Im guessing this is because of the recycling of the itemrenderers?