Go Back   CodingForums.com > :: Client side development > Flash & ActionScript > Adobe Flex

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-17-2011, 05:03 PM   PM User | #1
bon_t
New Coder

 
Join Date: Jul 2010
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
bon_t is an unknown quantity at this point
How to apply different formatting to TextArea content

Hello,

I have a TextArea component called labels that will be populated by Strings in an Array called labelsArray.

Example of labelsArray content:
Code:
private var labelsArray:Array = new Array( "apple", "*banana", "carrot" );
Initially, I populated labels with this statement:
Code:
labels.text = labelsArray.join( "\n" );
If the String is preceded by an asterisk(*) - as is the case with "banana" in the sample content - that String needs to be in a different color AND be surrounded by square brackets []. The asterisk itself is not displayed.

I was not able to find any formatting applied to Strings.

I found out about the TextFormat class to be applied to TextField objects with setTextFormat.

I also found out about the TextLayoutFormat class to be applied to TextArea objects with setFormatOfRange. Unfortunately, I don't under the explanations given for the parameters of setFormatOfRange:

setFormatOfRange( format, anchorPosition, activePosition )
anchorPosition - A character position, relative to the beginning of the text String, specifying the end of the selection that stays fixed when the selection is extended with the arrow keys.
activePosition - A character position, relative to the beginning of the text String, specifying the end of the selection that moves when the selection is extended with the arrow keys.

I don't understand starting from "...specifying the end..." to the end. I don't understand how arrow keys come into play with formatting of text.

Is there something much simpler than this? I'm hoping to loop through labelsArray and apply formatting if needed on each String, and then concatenating/appending it to labels.text.

Thanks for your help!
Bonnie
bon_t is offline   Reply With Quote
Old 05-19-2011, 06:58 PM   PM User | #2
bon_t
New Coder

 
Join Date: Jul 2010
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
bon_t is an unknown quantity at this point
With some external help, I've figured this out and would like to share my solution.

If you are using a Halo (mx) TextArea component, then you can simply use the htmlText attribute, which is a String, and set your xml marked-up String to this attribute.

However, if you are using a Spark TextArea component, the htmlText attribute no longer exists. You have to set the textFlow attribute. And you do this indirectly with the following command:

Code:
<TextArea component>.textFlow = spark.utils.TextFlowUtil.importFromString( <htmlTextString> );
I hope this helps others out,
Bonnie
bon_t is offline   Reply With Quote
Reply

Bookmarks

Tags
format, textarea, textlayoutformat

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:32 AM.


Advertisement
Log in to turn off these ads.