The following example shows how you can change the direction of a FormItem container in Flex by setting the direction property to “horizontal” or “vertical”.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/03/18/changing-the-layout-direction-of-a-form-item-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Style>
        FormItem {
            labelStyleName: myFormItemLabelStyleName;
        }

        .myFormItemLabelStyleName {
            fontWeight: bold;
        }
    </mx:Style>

    <mx:Form id="form">
        <mx:FormItem label="horizontal:"
                direction="horizontal">
            <mx:Image source="{Icons.AIR_ICON}"
                    toolTip="Adobe AIR" />
            <mx:Image source="{Icons.FLASH_ICON}"
                    toolTip="Adobe Flash" />
            <mx:Image source="{Icons.FLASH_PLAYER_ICON}"
                    toolTip="Adobe Flash Player" />
            <mx:Image source="{Icons.FLEX_ICON}"
                    toolTip="Adobe Flex" />
        </mx:FormItem>
        <mx:FormItem label="vertical:"
                direction="vertical">
            <mx:Image source="{Icons.AIR_ICON}"
                    toolTip="Adobe AIR" />
            <mx:Image source="{Icons.FLASH_ICON}"
                    toolTip="Adobe Flash" />
            <mx:Image source="{Icons.FLASH_PLAYER_ICON}"
                    toolTip="Adobe Flash Player" />
            <mx:Image source="{Icons.FLEX_ICON}"
                    toolTip="Adobe Flex" />
        </mx:FormItem>
    </mx:Form>

</mx:Application>

/src/Icons.as

/** http://blog.flexexamples.com/2008/03/18/changing-the-layout-direction-of-a-form-item-in-flex/ */
package {
    [Bindable]
    public class Icons {
        public function Icons() {
        }

        [Embed("assets/air_appicon-tn.gif")]
        public static var AIR_ICON:Class;

        [Embed("assets/fl_appicon-tn.gif")]
        public static var FLASH_ICON:Class;

        [Embed("assets/fl_player_appicon-tn.gif")]
        public static var FLASH_PLAYER_ICON:Class;

        [Embed("assets/fx_appicon-tn.gif")]
        public static var FLEX_ICON:Class;
    }
}

View source is enabled in the following example.

 
Tagged with:
 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

One Response to Changing the layout direction of a form item in Flex

  1. Alex C says:

    Very handy! Didn’t know about this attribute of the FormItem. Thanks :-)

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree