Search code examples
actionscript-3flashtextareamxml

How can you make a TextArea's htmlText change, based upon a variable?


Let's say you want to use a single label whose text changes in real-time, based on the value of a variable, which is pretty easy to do in AS3. But let's say you want part of the text to be in regular font-weight, and you want the other part to be in bold. I'm assuming a TextArea with an htmlText value is necessary, to maintain the bold / not bold parts within the single label, but I don't see how to make the data in there change, based upon a variable, like you can with an ordinary text attribute.

How can this be done?


Solution

  • var firstPart:String = "someText";
    var boldPart:String = "this is bold";
    text.htmlText = firstPart + "<b>" + boldPart + "</b>";
    

    You can also use setTextFormat to make only a part of a text in a textfield bold:

    var tf:TextFormat = new TextFormat();
    tf.bold = true;
    textField.setTextFormat(tf,10,20); // makes chars from 10 to 20 bold