0
for(var temp:int = 0;temp<recipeNum;temp++)
{
    if ((temp == 1) || (temp == 2) || (temp == 6) || (temp == 9))   
    {
        textRecipe.textColor = 0x0000FF;
    }
    else
    {
        textRecipe.textColor = 0x000000;
    }

    textRecipe.text += "\n" + recipe[temp];
    addChild(textRecipe);                   
}

此代码的问题是屏幕上的所有文本都是黑色的。我希望 temp 1,2,6,9 为蓝色,任何解决方案。

4

1 回答 1

3

如果我没记错的话,您只使用了一个TextField名为textRecipe.

请注意,即使您将 recipeNum 时间添加到舞台,它也始终是同一个对象。

分配textColor属性,它会修改整个文本的颜色,因此最后分配的颜色(可能是黑色)将是整个文本的颜色。

使用多个TextField或使用 aTextFormat为文本的一部分分配颜色:

var myFormat = new TextFormat();
myFormat.color = 0x0000FF;

textRecipe.setTextFormat(myFormat, 5, 8);  //sets color blue to chars from 5 to 8

如果您需要更多帮助,请告诉我。

于 2012-12-05T10:51:29.127 回答