如何根据变量进行TextArea的htmlText更改?

时间:2012-10-19 14:43:20

标签: actionscript-3 flash textarea mxml

假设您想要使用单个标签,其文本会根据变量的值实时更改,这在AS3中非常容易实现。但是,假设您希望文本的一部分采用常规字体粗细,并且您希望其他部分以粗体显示。我假设一个带有htmlText值的TextArea是必要的,以保持单个标签内的粗体/非粗体部分,但我不知道如何根据变量使数据在那里变化,就像你可以普通的文本属性。

如何做到这一点?

1 个答案:

答案 0 :(得分:2)

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

您还可以使用setTextFormat仅以文本字段粗体显示文本的一部分:

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