22
Apr
08

Setting the letter spacing in the RichTextEditor control in Flex

The following example shows how you can set the letter spacing in a Flex RichTextEditor control by setting the textAreaStyleName and letterSpacing styles.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/04/22/setting-the-letter-spacing-in-the-richtexteditor-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Style>
        .myTextAreaStyleName {
            fontFamily: Courier;
            letterSpacing: 3; /* pixels */
        }
    </mx:Style>

    <mx:Script>
        <![CDATA[
            import mx.events.SliderEvent;

            private function slider_change(evt:SliderEvent):void {
                var cssStyle:CSSStyleDeclaration = StyleManager.getStyleDeclaration(".myTextAreaStyleName");
                cssStyle.setStyle("letterSpacing", evt.value);
            }
        ]]>
    </mx:Script>

    <mx:String id="str" source="lorem.txt" />

    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="letterSpacing:">
                <mx:HSlider id="slider"
                        minimum="0"
                        maximum="20"
                        value="3"
                        liveDragging="true"
                        snapInterval="1"
                        tickInterval="1"
                        change="slider_change(event);" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:RichTextEditor id="richTextEditor"
            text="{str}"
            textAreaStyleName="myTextAreaStyleName"
            width="100%"
            height="100%" />

</mx:Application>

View source is enabled in the following example.


5 Responses to “Setting the letter spacing in the RichTextEditor control in Flex”


  1. 1 Klaus Busse Apr 23rd, 2008 at 1:24 am

    Nice example, however I’m wondering why it takes so long to load. Has letter spacing relevant impact on rendering time?

    Thanks

    Klaus

  2. 2 Anonymous Apr 23rd, 2008 at 5:05 pm

    not so rich ;) it doesnt do hold-delete on the keyboard

  3. 3 Marcio Apr 24th, 2008 at 10:18 am

    ?

    How to condense white space around HTML tags or TXT using the Flex RichTextEditor control

    ?

  4. 4 peterd Apr 24th, 2008 at 4:54 pm
  5. 5 Ivan Apr 29th, 2008 at 2:19 am

    If I trying to change sont size, and after that change spacing
    then font size changes to its initial size.

    p.s. sorry for for English, my native language is php :)

Leave a Reply

This blog is terrible at eating HTML tags. If you plan on posting code/XML, please escape your "<" characters as "&lt;" and your ">" characters as "&gt;".