Setting the text rotation on a TextGraphic control in Flex Gumbo

The following example shows how you can set the text rotation on a Flex Gumbo TextGraphic control by setting the textRotation style.

Full code after the jump.

To use the following code, you must have Flash Player 10 and a Flex Gumbo SDK installed in your Flex Builder 3. For more information on downloading and installing the Gumbo SDK into Flex Builder 3, see “Using the beta Gumbo SDK in Flex Builder 3”.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/11/02/setting-the-text-rotation-on-a-textgraphic-control-in-flex-gumbo/ -->
<FxApplication name="TextGraphic_textRotation_test"
        xmlns="http://ns.adobe.com/mxml/2009">
    <layout>
        <BasicLayout />
    </layout>

    <Declarations>
        <Array id="arr">
            <Object label="auto" />
            <Object label="rotate0" />
            <Object label="rotate90" />
            <Object label="rotate180" />
            <Object label="rotate270" />
        </Array>
    </Declarations>

    <Form>
        <FormItem label="textRotation:">
            <ComboBox id="comboBox"
                    dataProvider="{arr}" />
        </FormItem>
    </Form>

    <TextGraphic id="textGraphic"
            text="{Capabilities.version}"
            textRotation="{comboBox.selectedItem.label}"
            horizontalCenter="0"
            verticalCenter="0" />

</FxApplication>

View source is enabled in the following example.

You can also set the textRotation style in an external .CSS file or <Style/> block, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/11/02/setting-the-text-rotation-on-a-textgraphic-control-in-flex-gumbo/ -->
<FxApplication name="TextGraphic_textRotation_test"
        xmlns="http://ns.adobe.com/mxml/2009">
    <layout>
        <BasicLayout />
    </layout>

    <Style>
        TextGraphic {
            textRotation: "rotate180";
        }
    </Style>

    <TextGraphic id="textGraphic"
            text="{Capabilities.version}"
            horizontalCenter="0"
            verticalCenter="0" />

</FxApplication>

Or, you can set the textRotation style using ActionScript, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/11/02/setting-the-text-rotation-on-a-textgraphic-control-in-flex-gumbo/ -->
<FxApplication name="TextGraphic_textRotation_test"
        xmlns="http://ns.adobe.com/mxml/2009">
    <layout>
        <BasicLayout />
    </layout>

    <Script>
        <![CDATA[
            import mx.events.ListEvent;

            private function comboBox_change(evt:ListEvent):void {
                var value:String = comboBox.selectedItem.label;
                textGraphic.setStyle("textRotation", value);
            }
        ]]>
    </Script>

    <Declarations>
        <Array id="arr">
            <Object label="auto" />
            <Object label="rotate0" />
            <Object label="rotate90" />
            <Object label="rotate180" />
            <Object label="rotate270" />
        </Array>
    </Declarations>

    <Form>
        <FormItem label="textRotation:">
            <ComboBox id="comboBox"
                    dataProvider="{arr}"
                    change="comboBox_change(event);" />
        </FormItem>
    </Form>

    <TextGraphic id="textGraphic"
            text="{Capabilities.version}"
            horizontalCenter="0"
            verticalCenter="0" />

</FxApplication>

Due to popular demand, here is the “same” example in a more ActionScript friendly format:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/11/02/setting-the-text-rotation-on-a-textgraphic-control-in-flex-gumbo/ -->
<FxApplication name="TextGraphic_textRotation_test"
        xmlns="http://ns.adobe.com/mxml/2009"
        initialize="init();">
    <layout>
        <BasicLayout />
    </layout>

    <Script>
        <![CDATA[
            import flash.text.engine.TextRotation;
            import mx.controls.ComboBox;
            import mx.containers.Form;
            import mx.containers.FormItem;
            import mx.events.ListEvent;
            import mx.graphics.TextGraphic;

            private var arr:Array;
            private var comboBox:ComboBox;
            private var textGraphic:TextGraphic;

            private function init():void {
                arr = [];
                arr.push({label:TextRotation.AUTO});
                arr.push({label:TextRotation.ROTATE_0});
                arr.push({label:TextRotation.ROTATE_90});
                arr.push({label:TextRotation.ROTATE_180});
                arr.push({label:TextRotation.ROTATE_270});

                comboBox = new ComboBox();
                comboBox.dataProvider = arr;
                comboBox.addEventListener(ListEvent.CHANGE,
                            comboBox_change);

                var formItem:FormItem = new FormItem();
                formItem.label = "textRotation:";
                formItem.addChild(comboBox);

                var form:Form = new Form();
                form.addChild(formItem);
                addItem(form);

                textGraphic = new TextGraphic();
                textGraphic.text = Capabilities.version;
                textGraphic.horizontalCenter = 0;
                textGraphic.verticalCenter = 0;
                addItem(textGraphic);
            }

            private function comboBox_change(evt:ListEvent):void {
                var value:String = comboBox.selectedItem.label;
                textGraphic.setStyle("textRotation", value);
            }
        ]]>
    </Script>

</FxApplication>

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

2 thoughts on “Setting the text rotation on a TextGraphic control in Flex Gumbo

  1. I want to use Gumbo new text engine to test Japanese vertical writing.

    I used textRotation=”rotate270″ and rotation=”90″ in FxTextArea component,

    and it looks ok , but it not equal to Adobe’s video in the middle of “http://www.adobe.com/jp/devnet/logged_in/jchurch_flashplayer10.html”

    How can I write Japanese ( or other Asian language ) vertical writing?

Comments are closed.