Skipping super.data = value in item renderer when value is null
Problem
I am seeing some runtime errors (RTEs) with the data or listData properties when I use my DataGrid or AdvancedDataGrid with a custom item renderer.
Solution
Verify that your code always preserves the value that the grid sets data and listData to in your setter.
Explanation
This is critical because the data grids assume that when they set the data and listData properties that their value will be retained. If you are overriding an IDropInListItemRenderer these components assume that the data and listData properties will stay synchronized.
This can happen for several reasons, two of which I have seen implemented or implemented myself. The first reason is that you expect data to be a particular class and you are checking this assumption. If the value passed in is not the right type, then you store a null instead of the passed in value (or ignore the new value).
override public function set data(value:Object):void
{
if (value is MyType) {
super.data = value;
_mydata = value;
} else {
super.data = null;
_mydata = null;
}
}
The solution is for this code to always set super.data regardless of the type of value
override public function set data(value:Object):void
{
super.data = value;
if (value is MyType) {
_mydata = value;
} else {
_mydata = null;
}
}
A similar problem can occur if you are checking for null and not updating the super.data value. Just remember, always store and report the actual value that data is set to, even if you will decide to ignore it in your renderer. This is important for both fully custom item renderers (when you subclass UIComponent for example) and when you subclass an existing item renderer (such as Label, which implements IDataRenderer, IDropInListItemRenderer, and IListItemRenderer).
