actionscript-3 - 使用 Actionscript 3 在一个文本字段中使用两种颜色

标签 actionscript-3

是否可以使用 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/

相关文章:

actionscript-3 - 在 AS3 中设置属性是否会阻止时间线补间?

apache-flex - Flex 对象创建实例数量加倍

ios - NetStream http 视频无法在 IOS 设备上播放

javascript - AS3 ByteArray 中这些 JavaScript 函数的等效调用是什么?

actionscript-3 - 游戏开发中的基于组件的架构

apache-flex - MXML 和 Actionscript3 有什么区别

actionscript-3 - 全局类的正确的面向对象结构

android - 如何使用 Adob​​e air - AS3 在静音模式下检测设备并与之交互

actionscript-3 - 在 Haxe 中为 Flash 符号创建一个类?

javascript - 如何将文本正文中的每个单词替换为另一个单词?