Setting the typographic case on a Spark Label control in Flex 4

The following example shows how you can set the typographic case (lowercase, uppercase, etc) on a Spark Label control in Flex 4 by setting the typographicCase style to one of the static constants in the flash.text.engine.TypographicCase class.

Full code after the jump.

The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.

For more information on getting started with Flex 4 and Flash Builder 4, see the official Adobe Flex Team blog.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/01/26/setting-the-typographic-case-on-a-spark-label-control-in-flex-4/ -->
<s:Application name="Spark_Label_typographicCase_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:controlBarContent>
        <s:DropDownList id="ddl"
                requireSelection="true"
                change="ddl_changeHandler(event);">
            <s:dataProvider>
                <s:ArrayList>
                    <fx:Object label="{TypographicCase.DEFAULT}" />
                    <fx:Object label="{TypographicCase.CAPS}" />
                    <fx:Object label="{TypographicCase.CAPS_AND_SMALL_CAPS}" />
                    <fx:Object label="{TypographicCase.LOWERCASE}" />
                    <fx:Object label="{TypographicCase.SMALL_CAPS}" />
                    <fx:Object label="{TypographicCase.TITLE}" />
                    <fx:Object label="{TypographicCase.UPPERCASE}" />
                </s:ArrayList>
            </s:dataProvider>
        </s:DropDownList>
    </s:controlBarContent>
 
    <fx:Script>
        <![CDATA[
            import flash.text.engine.TypographicCase;
            import spark.events.IndexChangeEvent;
 
            protected function ddl_changeHandler(evt:IndexChangeEvent):void {
                if (ddl.selectedItem) {
                    lbl.setStyle("typographicCase", ddl.selectedItem.label);
                }
            }
        ]]>
    </fx:Script>
 
    <fx:Style>
        @font-face {
            src: url("C:/Windows/fonts/ArnoPro-Regular.otf");
            fontFamily: ArnoEmbedded;
            embedAsCFF: true;
            unicodeRange: U+0020-007E; /* englishRange */
        }
    </fx:Style>
 
    <s:Label id="lbl"
            text="The quick brown fox jumps over the lazy dog."
            fontFamily="ArnoEmbedded"
            fontSize="72"
            width="90%"
            horizontalCenter="0" verticalCenter="0" />
 
</s:Application>

Or you can set the typographicCase style in an external .CSS file or <Style/> block, as seen in the following example:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/01/26/setting-the-typographic-case-on-a-spark-label-control-in-flex-4/ -->
<s:Application name="Spark_Label_typographicCase_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">
 
    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
 
        @font-face {
            src: url("C:/Windows/fonts/ArnoPro-Regular.otf");
            fontFamily: ArnoEmbedded;
            embedAsCFF: true;
            unicodeRange: U+0020-007E; /* englishRange */
        }
 
        s|Label {
            fontFamily: ArnoEmbedded;
            fontSize: 72;
            typographicCase: capsAndSmallCaps;
        }
    </fx:Style>
 
    <s:Label id="lbl"
            text="The quick brown fox jumps over the lazy dog."
            width="90%"
            horizontalCenter="0" verticalCenter="0" />
 
</s:Application>

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