Creating a bitmap background fill on a Spark List control in Flex 4

The following example shows how you can set a bitmap background fill on a Spark List control in Flex 4 by creating a custom Spark List skin with a BitmapFill object and setting a custom item renderer.

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_background_BitmapFill_test"
    <s:List id="list"
            <s:VerticalLayout gap="0" horizontalAlign="contentJustify" requestedRowCount="5" />

The custom Spark List skin file, skins/CustomListSkin.mxml, is as follows:

<?xml version="1.0" encoding="utf-8"?>
<!-- -->
<s:SparkSkin name="CustomListSkin"
        <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.alpha = getStyle("borderAlpha");
                borderStroke.color = getStyle("borderColor");
                super.updateDisplayList(unscaledWidth, unscaledHeight);
        <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" source="@Embed('pattern_149.gif')" fillMode="repeat" />
    <!--- The Scroller component to add scroll bars to the list. -->
    <s:Scroller id="scroller"
                left="0" top="0" right="0" bottom="0"
        <s:DataGroup id="dataGroup" itemRenderer="spark.skins.spark.DefaultItemRenderer">
                <!--- 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 item renderer, skins/CustomItemRenderer.mxml, is as follows:

<?xml version="1.0" encoding="utf-8"?>
<!-- -->
<s:ItemRenderer name="CustomItemRenderer"
    <!-- states -->
        <s:State name="normal" stateGroups="normalStates" />
        <s:State name="hovered" stateGroups="hoveredStates" />
        <s:State name="selected" stateGroups="selectedStates" />
        <s:State name="normalAndShowsCaret" stateGroups="normalStates,caretStates" />
        <s:State name="hoveredAndShowsCaret" stateGroups="hoveredStates,caretStates"/>
        <s:State name="selectedAndShowsCaret" stateGroups="selectedStates,caretStates"/>
    <s:Rect left="0" right="0" top="0" bottom="0">
            <s:SolidColorStroke color="{getStyle('selectionColor')}"
            <s:SolidColor color.normalStates="{getStyle('contentBackgroundColor')}"
    <s:Label id="labelDisplay"
            left="3" right="3" 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.

3 thoughts on “Creating a bitmap background fill on a Spark List control in Flex 4

  1. Hi Peter,

    could you give me a hint on how the item renderer has access to the property selectionColor for example? I’m using the Flex 4.0 SDK 14159 and the compiler produces an error 1120: Access of undefined property selectionColor. I have the same issue with contentBackgroundColor and rollOverColor. In your online example it works perfectly and I have tried to rebuild that example without any changes but it won’t run. Do you think it is a problem with the SDK version? Even if it would run I’d wonder how the item renderer can be aware of these properties?!

    Thanks and best regards!

    1. @Thilo,

      Nope, just looks like the APIs changed between the time I originally wrote the example and when Flex 4.0 shipped.
      I updated the code above so it should work in the final Flex SDK and the Flex SDK. I’ll work on updating the SWF/ZIP too at some point.


  2. You can also create a custom bitmap fill item renderer in ActionScript, as seen in the following example:

    package {
        import spark.components.ResizeMode;
        import spark.skins.spark.ListSkin;
        public class CustomListSkinAS extends ListSkin {
            protected var bmpFill:BitmapFill;
            protected const img:Class;
            public function CustomListSkinAS() {
                bmpFill = new BitmapFill();
                bmpFill.alpha = 0.3;
                bmpFill.fillMode = BitmapFillMode.REPEAT;
                bmpFill.source = img;
                background.fill = bmpFill;


Comments are closed.