Setting a bitmap image fill on a Spark FormHeading control in Flex Hero

The following example shows how you can set a bitmap image fill on a Spark FormHeading control in Flex Hero by creating a custom FormHeading skin and creating a repeating BitmapFill object.

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

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/09/01/setting-a-bitmap-image-fill-on-a-spark-formheading-control-in-flex-hero/ -->
<s:Application name="Spark_FormHeading_BitmapFill_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx">
    <s:layout>
        <s:VerticalLayout horizontalAlign="center" verticalAlign="middle" />
    </s:layout>
 
    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
 
        s|FormHeading {
            backgroundAlpha: 0.4;
            skinClass: ClassReference("skins.CustomSparkFormHeadingSkin");
        }
    </fx:Style>
 
    <s:Form id="frm" defaultButton="{submitBtn}" backgroundColor="#EEEEEE">
        <s:FormHeading id="fh1"
                label="Spark Form Heading" />
        <s:FormItem sequenceLabel="1." label="Username:" required="true">
            <s:helpContent>
                <s:Label text="user@domain.com" />
            </s:helpContent>
            <s:TextInput id="username" />
        </s:FormItem>
        <s:FormItem sequenceLabel="2." label="Password:" required="true">
            <s:helpContent>
                <s:Label text="weak" color="red" />
            </s:helpContent>
            <s:TextInput id="password1" displayAsPassword="true" />
        </s:FormItem>
        <s:FormItem sequenceLabel="3." label="Confirm password:">
            <s:helpContent>
                <s:HGroup>
                    <s:Label text="One" color="red" />
                    <s:Label text="Two" color="blue" />
                </s:HGroup>
            </s:helpContent>
            <s:TextInput id="password2" displayAsPassword="true" />
        </s:FormItem>
        <s:FormItem>
            <s:layout>
                <s:HorizontalLayout />
            </s:layout>
            <s:Button id="resetBtn" label="Reset" />
            <s:Button id="submitBtn" label="Submit" />
        </s:FormItem>
    </s:Form>
 
</s:Application>

And the custom Spark FormHeading skin class, skins/CustomSparkFormHeadingSkin.mxml, is as follows:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/09/01/setting-a-bitmap-image-fill-on-a-spark-formheading-control-in-flex-hero/ -->
<s:Skin name="CustomSparkFormHeading"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx"
        xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
        alpha.disabled="0.5">
    <s:states>
        <s:State name="normal" />
        <s:State name="disabled" />
    </s:states>
    <s:layout>
        <s:FormItemLayout>
            <s:constraintColumns>
                <s:ConstraintColumn id="sequenceCol" />
                <s:ConstraintColumn id="labelCol" />
                <s:ConstraintColumn id="contentCol"/>
                <s:ConstraintColumn id="helpCol"/>
            </s:constraintColumns>
            <s:constraintRows>
                <s:ConstraintRow id="row1" />
            </s:constraintRows>
        </s:FormItemLayout>
    </s:layout>
 
    <fx:Metadata>
        [HostComponent("spark.components.FormHeading")]
    </fx:Metadata>
 
    <fx:Script fb:purpose="styling">
        <![CDATA[
            override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
                bgFill.alpha = getStyle("backgroundAlpha");
                super.updateDisplayList(unscaledWidth, unscaledHeight);
            }
        ]]>
    </fx:Script>
 
    <!--- Defines the appearance of the Form class's background. -->
    <s:Rect id="background" left="0" right="0" top="0" bottom="0">
        <s:fill>
            <s:BitmapFill id="bgFill" source="@Embed('assets/pattern_149.gif')" fillMode="repeat" />
        </s:fill>
    </s:Rect>
 
    <s:Label id="labelDisplay"
            left="labelCol:0" right="helpCol:10" top="row1:10" bottom="row1:10" />
 
</s:Skin>

This entry is based on a beta version of the Flex Hero 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 Hero SDK.