Setting the letter spacing in the RichTextEditor control in Flex

by Peter deHaan on April 22, 2008

in CSSStyleDeclaration, RichTextEditor, StyleManager, TextArea, getStyleDeclaration()

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.

{ 9 comments… read them below or add one }

1 Klaus Busse April 23, 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

Reply

2 Anonymous April 23, 2008 at 5:05 pm

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

Reply

3 Marcio April 24, 2008 at 10:18 am

?

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

?

Reply

4 peterd April 24, 2008 at 4:54 pm
5 Ivan April 29, 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 :)

Reply

6 Marcio November 17, 2008 at 10:26 am

How to apply line Spacing

I switch the code

from

import mx.events.SliderEvent;

private function slider_change(evt:SliderEvent):void {
var cssStyle:CSSStyleDeclaration = StyleManager.getStyleDeclaration(“.myTextAreaStyleName”);
cssStyle.setStyle(“letterSpacing”, evt.value);
}

to

import mx.events.SliderEvent;

private function slider_change(evt:SliderEvent):void {
var cssStyle:CSSStyleDeclaration = StyleManager.getStyleDeclaration(“.myTextAreaStyleName”);
cssStyle.setStyle(“lineSpacing”, evt.value);
}

But not have effect

Reply

7 Zmei November 23, 2008 at 4:42 pm

Yeah I was wondering about line spacing too. Can’t figure out how to change that. Anyone?

Reply

8 Zmei November 23, 2008 at 4:47 pm

Ok I just figured it out … just use CSS :)

.paragraphtext {
fontFamily: Georgia;
fontSize: 12;
color: #000000;
lineHeight: 14pt;
}

and then apply this style to your text (ex: )

Cheers!

Reply

9 Zmei November 23, 2008 at 4:52 pm

oh well … I guess I was wrong after all :)

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree

Previous post:

Next post: