Thanks a lot for your input guys. Nice example Andriy, but the viewsource
link is dead.

I think I found the simplest way of doing this: setFormatOfRange()

It basically changes the format (background/foreground) of a range of
characters in a RichEditableText component. So all I have to do is (from
inside RichEditableText):

var highlightFormat:TextLayoutFormat = new TextLayoutFormat();
highlightFormat.backgroundColor = 0xffee66;

var keywordsArray:Array = model.keywords.toLowerCase().split(' ');
var indexOfKeyword:int = 0;
for each (var currentKeyword:String in keywordsArray) {
 while((indexOfKeyword = this.text.toLowerCase().indexOf(currentKeyword,
indexOfKeyword)) >= 0) {
 this.setFormatOfRange(highlightFormat, indexOfKeyword, indexOfKeyword +
currentKeyword.length);
 indexOfKeyword++;
 }
}

Clean.

Reply via email to