开发者

ActionScript: How to apply different formatting to TextArea content

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

Example of labelsArray content:

private var labelsArray:Array = new Array( "apple", "*banana", "carrot" );

Initially, I populated labels with this statement:

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


One way is to use htmlText property.

myTextArea.htmlText = "<font color="red" size="12">String1</font>,
  <font color="green" size="11">String2</font>";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜