Search code examples
actionscript-3flashdynamic-text

How can i change color of one word in a dynamic textField in AS 3


I have this function:

private function boldVerb(_phrase:String, _verb:String):String
{
    var newHtmlText:String = "";

    var pattern:RegExp = new RegExp([_verb]);

    newHtmlText = _phrase.replace(pattern, "<b>" + _verb + "</b>");
    return newHtmlText;
}

And I want to change the color of this "verb" that the function receives. Is it possible in AS3?


Solution

  • Sure. You can either use a stylesheet or you use the font tag (assuming it's an html textfield).

    <font color='#FF0000'>This is red</font>
    

    See documentation here.