Fading an item renderer background fill on a Spark List control in Flex 4

The following example shows how you can fade an item renderer background fill on a Spark List control in Flex 4 by creating a custom item renderer, setting the Boolean autoDrawBackground property to false, drawing your own background fill, and then setting a fade transition from the normal and hovered states.

The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.

For more information on getting started with Flex 4 and Flash Builder 4, see the official Adobe Flex Team blog.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/06/25/fading-an-item-renderer-background-fill-on-a-spark-list-control-in-flex-4/ -->
<s:Application name="Spark_List_itemRenderer_fade_test"
    <s:List id="lst"
            horizontalCenter="0" verticalCenter="0">
            <s:VerticalLayout gap="0"
                    requestedRowCount="7" />
            <s:ArrayList source="[One,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten]" />

And the custom Spark List item renderer, skins/FadingItemRenderer.mxml, is as follows:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/06/25/fading-an-item-renderer-background-fill-on-a-spark-list-control-in-flex-4/ -->
<s:ItemRenderer name="FadingItemRenderer"
        <s:State name="normal" />
        <s:State name="hovered" />
        <s:State name="selected" />
        <s:Transition fromState="normal" toState="hovered" autoReverse="true">
            <s:Fade target="{bgRect}" duration="600" />
    <s:Rect id="bgRect"
            left="0" right="0" top="0" bottom="0">
            <s:SolidColor color="{getStyle('rollOverColor')}"
                          color.selected="{getStyle('selectionColor')}" />
    <s:Label id="labelDisplay"
            left="5" right="5" top="5" bottom="4" />


View source is enabled in the following example.

This entry is based on a beta version of the Flex 4 SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex 4 SDK.