2012-12-05 63 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 

讓我知道如果你需要更多的幫助。