是否可以使用 Actionscript 3.0 在一个文本字段中包含两种文本颜色?
例如:我怎样才能让第一根弦变黑,第二根弦变红?
这是我使用单一颜色时的代码:
public function logs(txt)
{
if (txt == '')
{
textLog.text = "Let's Open up our treasure boxes !!!";
}
else
{
textLog.text = '' + txt + '';
}
textLog.x = 38.60;
textLog.y = 60.45;
textLog.width = 354.50;
textLog.height = 31.35;
textLog.selectable = false;
textLog.border = false;
var format:TextFormat = new TextFormat();
var myFont:Font = new Font1();
format.color = 0x000000;
format.font = myFont.fontName;
format.size = 18;
format.align = TextFormatAlign.CENTER;
format.bold = false;
textLog.embedFonts = true;
textLog.setTextFormat(format);
this.addChild(textLog);
}
最佳答案
在 setTextFormat
您可以指定开始索引和结束索引。您还可以使用 textLog.htmlText
将文本呈现为 html .
首先设置文字
var t:TextField = new TextField();
t.text = "BLUEGREEN";
addChild(t);
然后方法一
var format1:TextFormat = t.getTextFormat(0, 4);
format1.color = 0x0000ff;
t.setTextFormat(format1, 0, 4);
var format2:TextFormat = t.getTextFormat(5, t.length);
format2.color = 0x00ff00;
t.setTextFormat(format2, 5, t.length);
或者方法二
t.htmlText = '<font color="#0000ff">BLUE</font><font color="#00ff00">GREEN</font>';
关于actionscript-3 - 使用 Actionscript 3 在一个文本字段中使用两种颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8721523/