Are you thinking what this class does… ?
Well, in one of our project we had to develop a feature where we have a text area with text which has varying fontStyles, fontSize and fontWeight. Now the interesting part is to get these font styles on selection of a particular range of text from the Text control. I accidently stumbled upon TextRange class which proved to be a solution to my problem…..Just to test it I registered the mouseUp event on the text control and made the selectable property to true. As soon as I finish selecting a text, mouseup event handler should be called and in this handler function I wrote:

// txt is the id of the text control
var mySelectedTextRange:TextRange = new TextRange(txt, true);

So, by writing this I would be able to get the selected text as well as the fontfamily of the selected text in the Flex Builder console.
TextRange will take the following parameters – TextRange(owner:UIComponent, modifiesSelection:Boolean = false, beginIndex:int = -1, endIndex:int = -1).


Published by

Sunil Nair

I am a Software Developer currently working on developing Rich Internet Applications using Adobe Flex/AIR. I have had diverse experience of developing application in software industry for the last 4 years.

2 thoughts on “mx.controls.textClasses.TextRange”

  1. I agree with you about the feature of the class. But I think there is some problem when we trying to set and embedded font as fontFamily on selected text of an TextArea then it will not apply on the TextArea selected text.

  2. I guess you should have the answer now :).
    When you talk about using embedded fonts to apply fontfamily with textrange it is important that you set the embedFonts property of the textFeild to true.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s