Creating a stacked Spark Form container in Flex Hero

The following example shows how you can create a stacked Spark Form, FormHeading, and FormItem in Spark Hero by setting a the skinClass to the StackedFormSkin, StackedFormHeadingSkin, and StackedFormItem skins respectively.

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/08/30/creating-a-stacked-spark-form-container-in-flex-hero/ -->
<s:Application name="Spark_Form_skinClass_StackedFormSkin_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";
        @namespace mx "library://ns.adobe.com/flex/mx";
 
        s|Form {
            skinClass: ClassReference("spark.skins.spark.StackedFormSkin");
        }
 
        s|FormHeading {
            skinClass: ClassReference("spark.skins.spark.StackedFormHeadingSkin");
        }
 
        s|FormItem {
            skinClass: ClassReference("spark.skins.spark.StackedFormItemSkin");
        }
    </fx:Style>
 
    <s:Form id="frm" defaultButton="{submitBtn}" backgroundColor="#EEEEEE">
        <s:FormHeading label="Spark Form Heading" backgroundColor="haloSilver" />
        <s:FormItem sequenceLabel="1." label="Username:">
            <s:helpContent>
                <s:Label text="user@domain.com" />
            </s:helpContent>
            <s:TextInput id="username" />
        </s:FormItem>
        <s:FormItem sequenceLabel="2." label="Password:">
            <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>

You can also toggle the default Spark FormSkin skin and Spark StackedFormSkin at runtime using ActionScript, as seen in the following example:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/08/30/creating-a-stacked-spark-form-container-in-flex-hero/ -->
<s:Application name="Spark_Form_skinClass_StackedFormSkin_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>
    <s:controlBarContent>
        <s:CheckBox id="cb" label="Stacked forms?" change="cb_changeHandler(event);" />
    </s:controlBarContent>
 
    <fx:Script>
        <![CDATA[
            import spark.skins.spark.FormHeadingSkin;
            import spark.skins.spark.FormItemSkin;
            import spark.skins.spark.FormSkin;
            import spark.skins.spark.StackedFormHeadingSkin;
            import spark.skins.spark.StackedFormItemSkin;
            import spark.skins.spark.StackedFormSkin;
 
            protected function cb_changeHandler(evt:Event):void {
                var formCSS:CSSStyleDeclaration = styleManager.getStyleDeclaration("spark.components.Form");
                var formHeadingCSS:CSSStyleDeclaration = styleManager.getStyleDeclaration("spark.components.FormHeading");
                var formItemCSS:CSSStyleDeclaration = styleManager.getStyleDeclaration("spark.components.FormItem");
 
                if (cb.selected) {
                    formCSS.setStyle("skinClass", StackedFormSkin);
                    formHeadingCSS.setStyle("skinClass", StackedFormHeadingSkin);
                    formItemCSS.setStyle("skinClass", StackedFormItemSkin);
                } else {
                    formCSS.setStyle("skinClass", FormSkin);
                    formHeadingCSS.setStyle("skinClass", FormHeadingSkin);
                    formItemCSS.setStyle("skinClass", FormItemSkin);
                }
            }
        ]]>
    </fx:Script>
 
    <s:Form id="frm" defaultButton="{submitBtn}" backgroundColor="#EEEEEE">
        <s:FormHeading label="Spark Form Heading" backgroundColor="haloSilver" />
        <s:FormItem sequenceLabel="1." label="Username:">
            <s:helpContent>
                <s:Label text="user@domain.com" />
            </s:helpContent>
            <s:TextInput id="username" />
        </s:FormItem>
        <s:FormItem sequenceLabel="2." label="Password:">
            <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>

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.