Skip to main content
New Participant
April 15, 2010
Question

TextArea text highlight color, can you customize it and how?

  • April 15, 2010
  • 2 replies
  • 3949 views

== Environment

I'm using Flash CS4, Player 10 on a PC. Code is deployed to local webserver.

== Situation

I have a TextArea that is the receptacle for text loaded and parsed from an XML file delivered up by PHP.

The text contains HTML tags. I have edited the component so that the background of the TextArea component is black and the text is white. I set the background to black by clicking into the component itself, drilling down to the graphic element and changing the background color to black using the paint bucket in the color select control panel. I changed the text to white using a TextFormat line in ActionScript.

== The Goal

Change the color of the highlighting that occurs when a user clicks the mouse and drags across several words or lines. Because I change the colors of the text and background, one cannot see the words being highlighted although I have confirmed that one can select the words and copy them. For argument's sake, let's say I'd like to change the highlight to blue. 

(Extra credit: Is there a good way to set the background color of a text component in AS3? Extra Extra credit: Is there online docs that can teach me, fishing versus a menu and all that...)

== The Code

    // this line changes the contents of the text area based on a selection box
    info_txt.htmlText                   = reader.episodes[episode_cb.selectedIndex].description;

    // these two lines set up my font as Arial, 12 point, white

    var myFormat:TextFormat     = new TextFormat("Arial", 12, 0xFFFFFF);
    info_txt.setStyle("textFormat", myFormat);

    // This line ain't doin' squat!!!!!!!!!!!!!
    info_txt.setStyle("selectionColor", "0xFF0000"); 

Bueller? Pointers? Names of properties? Do I use a style sheet level property or a text format and where is any of this documented? I've spent perhaps three hours researching online. Several large "doh!" welts so far and very tired of answers from 2004...

This topic has been closed for replies.

2 replies

New Participant
January 17, 2011

This might help:

http://blog.flexexamples.com/2009/11/07/setting-the-selection-highlight-color-on-a-spark-richeditabletext-control-in-flex-4/

robdillon
Participating Frequently
April 15, 2010

The best solution for custom formatting on a textArea is to use a textField and a UIScrollBar instead. They are much more user friendly. Alternately, you can edit the textArea component to change the background color. To set a new color for a selection, you can use the selectionBeginIndex and selectionEndIndex to identify a subString of the text. Then you can apply a textFormat to that subString.

Look through the Flash help for TextArea, then google the property, method, event or style that looks interesting. You'll usually find someone who has written about it.