Using DataRenderer to add custom states to a spark List renderer
ItemRenderer has logic built in that changes between some standard states like normal, hovered, selected, etc. You can supplement this logic by overriding ItemRenderer.getCurrentRendererState(), or do away with the built in states altogether by subclassing DataRenderer instead of ItemRenderer.
DataRenderer is a simple class that extends Group and implements IDataRenderer. ItemRenderer extends DataRenderer and adds some useful functionality including managing the state of the renderer, drawing the background color, and adding properties like itemIndex.
The following example demonstrates a List that uses an item renderer that subclasses DataRenderer. Clicking on the radio buttons will change between the three states. Notice that the state doesn’t change when you hover over the renderer. Change DataRenderer to ItemRenderer and recompile to compare the difference in behavior when hovering over renderers.
This renderer saves the value of currentState into the data item and then restores that value in the set data method. This is needed to make the renderer capable of handling a virtual layout (the default in a spark List).
Note: This sample requires Flex SDK 4.0.0.13672 or higher. You can get the latest SDK builds from opensource.adobe.com.