Is there a way to customize the rollover and selected colors of an item renderer without losing the alternating background colors?
When i set the autoDrawBackground flag to false the roll over effects stops but for some reason the alternating background is also not drawn.
I would like to create a renderer which draws a white border on state hovered and a yellow border on selected instead of the default rollover color. I would also like to keep my alternating background colors i set on the list.
Any suggestions?
You could use the 'itemIndex' property of the ItemRenderer class to draw the background. For instance:
override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void
{
backgroundFill.color = itemIndex % 2 ? 0xff0000 : 0x00ff00;
super.updateDisplayList(unscaledWidth, unscaledHeight);
}
would alternate between red and green rows for a background graphic like this:
<s:Rect id="background" left="0" right="0" top="0" bottom="0">
<s:fill>
<s:SolidColor id="backgroundFill" />
</s:fill>
</s:Rect>
Using this technique, you could obviously do more complex things too, like gradients, alphas effects and so on.