Search code examples
flex4

Hgroup - how can I change order of elements?


When I create an HGroup and add elements to it, it adds the elements from left to right.

How can I change it to add Elements from right to left?


Solution

  • It sounds like you want to have the same controls and code as in usual MXML but with orientation of elements from right to left. So you need Flex SDK 4.1 and its Layout Mirroring feature. You can refer to the documentation how to use it.

    This is the quick sample code:

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx"
        xmlns:s="library://ns.adobe.com/flex/spark">
        <fx:Script>
        <![CDATA[
            [Bindable]
            private var currentDirection:String = "ltr";
        ]]>
        </fx:Script>
        <fx:Declarations>
            <s:RadioButtonGroup change="currentDirection = selectorsGroup.selectedValue.toString()" id="selectorsGroup" />
        </fx:Declarations>
        <mx:VBox horizontalCenter="0" verticalCenter="0">
            <s:HGroup id="controls" layoutDirection="{currentDirection}">
                <s:Button label="1" />
                <s:Button label="2" />
            </s:HGroup>
            <s:HGroup id="selectors">
                <s:RadioButton group="{selectorsGroup}" label="LTR" selected="true" value="ltr" />
                <s:RadioButton group="{selectorsGroup}" label="RTL" value="rtl" />
            </s:HGroup>
        </mx:VBox>
    </s:Application>