Setting the layout direction of a Flex ControlBar container

The following example shows how you can set the child layout direction of a ControlBar container in Flex by setting the direction property.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/02/13/setting-the-layout-direction-of-a-flex-controlbar-container/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Array id="arr">
        <mx:Object label="Button" />
        <mx:Object label="ButtonBar" />
        <mx:Object label="CheckBox" />
        <mx:Object label="ColorPicker" />
        <mx:Object label="ComboBox" />
        <mx:Object label="DataGrid" />
    </mx:Array>

    <mx:ApplicationControlBar dock="true">
        <mx:ToggleButtonBar id="toggleButtonBar"
                selectedIndex="1"
                itemClick="cBar.direction = event.label;">
            <mx:dataProvider>
                <mx:Array>
                    <mx:String>horizontal</mx:String>
                    <mx:String>vertical</mx:String>
                </mx:Array>
            </mx:dataProvider>
        </mx:ToggleButtonBar>
    </mx:ApplicationControlBar>

    <mx:Panel id="panel"
            width="320"
            height="160">
        <mx:List id="list"
                dataProvider="{arr}"
                width="100%"
                rowCount="{arr.length}" />
        <mx:ControlBar id="cBar"
                direction="vertical"
                horizontalAlign="right">
            <mx:Button label="Submit" />
            <mx:Button label="Cancel" />
        </mx:ControlBar>
    </mx:Panel>

</mx:Application>

View source is enabled in the following example.