Does anybody know how to apply a similar style of text highlighting to 
a Text component? 
This example uses TextField and I'd like to be able to do a similar 
highlight effect without rewriting the Highlighter component from 
FlexLib.

Initially tried setting the highlight in the htmlText but it 
apparently isn't supported.
Help please!


--- In [email protected], ibo <[EMAIL PROTECTED]> wrote:
>
> Have anyone worked on something like this before? What I want is to 
highlight the word by changing the background color of each keyword 
from a sentence/paragraph.
> 
> Here is my code so far:
> 
>           private function applyTextHighlight(textField:UIComponent, 
listOfWordPositions:Array):void {
>                var textArea:TextArea = TextArea(textField);
>                var tr:TextRange = new TextRange(textArea);
>                
>                tr.htmlText = textArea["htmlText"];
>                
>                for (var i:int=0; i<listOfWordPositions.length; i++) 
{        
>                   var metaWord:WordPositions = 
listOfWordPositions[i];
>                   tr.beginIndex = metaWord.startIndex;
>                   tr.endIndex = metaWord.endIndex;
>                   tr.htmlText = formattedText(tr.text, 
metaWord.color);               
>                      //tr["color"] = metaWord.color;
>                      //tr["fontWeight"] = "bold";
>                      //tr["fontSize"] = 12;
>                }                          
>           }
>           
>         private function formattedText(text:String, 
color:uint):String {
>             return "<FONT style='BACKGROUND-COLOR: " + color + "'>" 
+ text + "</FONT>";    
>         }
> 
> 
> TextRange seems to be very limited on how much you can format your 
html text so I'm not surprised it doesnt really fully support HTML. 
Any workaround to get a similar behavior?
> Changing the text color, size and weight works though (see commented 
out lines).
> 
> -Stephen
>

Reply via email to