2012-12-05 68 views
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);     
} 

该代码的问题屏幕上的所有文字都是黑色的。我想临时1,2,6,9是蓝色的,任何解决方案。如果语句改变文字颜色

回答

3

如果我没有错,您只使用一个名为textRecipeTextField

需要注意的是,即使你recipeNum次将其添加到舞台,它总是相同的对象。

指定textColor属性,它修改整个文本的颜色,所以最后分配的颜色(可能是黑色)将是整个文本的颜色。

要么使用一个以上的TextField或使用TextFormat指定颜色的文本的一部分:

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

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

让我知道如果你需要更多的帮助。