Creating a semi-transparent item renderer on a Spark List control in Flex 4

The following example shows how you can create a semi-transparent item renderer on a Spark List control in Flex 4 by creating a custom Spark List skin and a custom item renderer which sets the alpha property on the selected/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 To download the latest nightly build of the Flex 4 SDK, see

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"?>
<!-- -->
<s:Application name="Spark_List_itemRenderer_alpha_test"
    <s:List id="lst"
            horizontalCenter="0" verticalCenter="0">
            <s:VerticalLayout gap="0" horizontalAlign="justify" requestedRowCount="5" />
                <fx:Object label="One" />
                <fx:Object label="Two" />
                <fx:Object label="Three" />
                <fx:Object label="Four" />
                <fx:Object label="Five" />
                <fx:Object label="Six" />
                <fx:Object label="Seven" />
                <fx:Object label="Eight" />
                <fx:Object label="Nine" />

And the custom Spark List skin (which defines a background image fill for the List), skins/CustomListSkin.mxml, is as follows:

<?xml version="1.0" encoding="utf-8"?>
<!-- -->
<s:SparkSkin name="CustomListSkin"
    <!-- states -->
        <s:State name="normal" />
        <s:State name="disabled" />
    <fx:Script fb:purpose="styling">
            /* Define the skin elements that should not be colorized. 
            For list, the skin itself is colorized but the individual parts are not. */
            static private const exclusions:Array = ["scroller", "background"];
            override public function get colorizeExclusions():Array {
                return exclusions;
            /* Define the content fill items that should be colored by the "contentBackgroundColor" style. */
            static private const contentFill:Array = [];
            override public function get contentItems():Array {
                return contentFill;
            override protected function initializationComplete():void {
                useChromeColor = true;
            override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
                if (getStyle("borderVisible") == true) {
                    border.visible = true;
                    background.left = = background.right = background.bottom = 1;
                    scroller.minViewportInset = 1;
                } else {
                    border.visible = false;
                    background.left = = background.right = background.bottom = 0;
                    scroller.minViewportInset = 0;
                borderStroke.color = getStyle("borderColor");
                borderStroke.alpha = getStyle("borderAlpha");
                super.updateDisplayList(unscaledWidth, unscaledHeight);
        Defines the appearance of the the List's drop indicator.
        To customize the drop indicator appearance, create a custom ListSkin class.
        The List's layout takes care to size and position the dropIndicator.
        The size of the <code>dropIndicator</code> is typically set to the size of the gaps between the items.
        The minimum and maximum settings are typically respected only in the direction
        along the major axis (the gap axis).  For example a VerticalLayout ignores the 
        <code>minWidth</code> and <code>maxWidth</code> settings, 
        but respect <code>minHeight</code> and <code>maxHeight</code>.
        <fx:Component id="dropIndicator">
            <s:Group minWidth="3" minHeight="3" maxWidth="3" maxHeight="3">
                <s:Rect left="0" right="0" top="0" bottom="0">
                        <!--- Defines the color of the background. -->
                        <s:SolidColor color="0xBBBBBB" />
                        <s:SolidColorStroke color="0x868686" weight="1"/>
    <!-- border -->
    <s:Rect left="0" right="0" top="0" bottom="0" id="border">
            <s:SolidColorStroke id="borderStroke" weight="1"/>
    <!-- fill -->
    <!--- Defines the background appearance of the list-based component. -->
    <s:Rect id="background" left="1" right="1" top="1" bottom="1" >
            <s:BitmapFill id="bgFill"
                    fillMode="repeat" />
    <!--- The Scroller component to add scroll bars to the list. -->
    <s:Scroller id="scroller"
            left="0" top="0" right="0" bottom="0"
            minViewportInset="1" hasFocusableChildren="false">
        <s:DataGroup id="dataGroup"
                <!--- The default layout is vertical and measures at least for 5 rows.  
                When switching to a different layout, HorizontalLayout for example,
                make sure to adjust the minWidth, minHeihgt sizes of the skin -->
                <s:VerticalLayout gap="0" horizontalAlign="contentJustify" requestedMinRowCount="5" />

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

<?xml version="1.0" encoding="utf-8"?>
<!-- -->
<s:ItemRenderer name="CustomItemRenderer"
        <s:State name="normal" />
        <s:State name="hovered" />
        <s:State name="selected" />
    <s:Rect left="0" right="0" top="0" bottom="0"
            <s:SolidColor color="haloBlue"
                    alpha="0.4" alpha.selected="0.6" />
    <s:Label text="{data.label}"
            left="2" right="2" top="4" bottom="4" />

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.

One thought on “Creating a semi-transparent item renderer on a Spark List control in Flex 4

Comments are closed.