How do I alternate text colors in a dynamic text field I tried to use CSS but it changes all the text to the same color i want each line to be a seperate color.
Printable View
How do I alternate text colors in a dynamic text field I tried to use CSS but it changes all the text to the same color i want each line to be a seperate color.
Make sure the text field is HTML enabled.
This function reads a string, and out puts a html formatted string based on the two colours you give it:
Code:var myString = "this is some text\nthis is some text\nthis is some text\nthis is some text\nthis is some text";
function alternateTextColour(s:String, colour1:uint, colour2:uint):String {
var a:Array = s.split("\n");
var toReturn:String = "";
trace(a);
t.text = "";
for(var z:int = 0; z<a.length; z++) {
toReturn += "<font color=\"#"+(z&1?colour1.toString(16):colour2.toString(16))+"\">"+a[z]+"</font>\n";
}
return toReturn;
}
t.htmlText = alternateTextColour(myString, 0xFF0000, 0xFF);
thanks works beautifully
No worries. Obviously the trace isn't needed.
I've also spotted a little error, changing:
toCode:colour1.toString(16):colour2.toString(16)
will mean the first line's colour will be colour1.Code:colour2.toString(16):colour1.toString(16)