Here's the high level version of the question (hopefully this will help you decide whether to read the rest of the post, which is a bit long, or not):
What is the most efficient (and proper) way to write an itemRenderer for a set of ADG columns that properly refreshes when an ADG variable pointing to a specific cell changes? The code below is how I've solved the problem, and seems to work, but I am concerned it may be too slow or simply too convoluted of a way to solve the problem.
OK, if you've decided to read on: I'm using an itemRenderer that will color one cell of my ADG depending on some condition being met. The ADG keeps track of the cell to be colored differently using a column index (we'll assume that the cell has to belong to the row currently selected). I realize that I can turn on singleCell selection and accomplish something similar, but that won't work for me here.
The itemRenderer code is here
public class CellItemRenderer extends Label
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
var g:Graphics = graphics;
var grid1:AdvancedDataGridFB = MyAdvancedDataGrid(DataGridListData(listData).owner);
var s:String = DataGridListData(listData).dataField;
if (grid1.isColored(data, s))
g.drawRect(0, 0, unscaledWidth, unscaledHeight);
function isColored checks whether the cell is the one that should have a different color by checking if it's in the selected row and it its column index == coloredCellColumn, and if so it returns true.
public function isColored (data:Object, df:String):Boolean
var retVal:Boolean = false;
var col:AdvancedDataGridColumn = columns[coloredCellColumn];
// get the associated dataField
var preselectedDataField:String = col.dataField;
if (preselectedDataField == df)
retVal = true;
The colored cell can move left / right using keys by listening to the keydown event on the ADG and moving coloredCellColumn left / right. This all seems to work fine. Except that every time the keys are used to move the cell left / right I need to call invalidateList() on the ADG for the itemRenderer to refresh and things seem a little slow, so I've been trying to understand whether the path I've taken here actually makes any sense or not. Here are my (newbie worthy) questions:
- why do I need to force an invalidate on the ADG? I sort of assumed that the index would be marked as a property of the ADG, and thus the invalidate / validate cycle would run its normal course, instead of waiting for me to refresh stuff.
- why does invalidateList seem to be the only command that does the trick? I've tried ValidateNow, invalidateDisplayList, invalidateProperties, and validateDisplayList but none of them seem to have any effect - reading the various documents on life cycle of a component I sort of assumed that they would. I read this post and Mike's answer scared me more than anything else - am I reloading all the data? that would seem super inefficient.
- Is there an obvious way to do this that is simple, fast, easy? Flex seems to have a lot of awesome ways to solve problems but I have a hard time finding out what they're called.
Would love to hear any expert advice.