Click to See Complete Forum and Search --> : [RESOLVED] alternate text colors.
calmchess
09-14-2009, 10:37 PM
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.
dudeqwerty
09-15-2009, 06:30 AM
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:
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);
calmchess
09-15-2009, 09:53 AM
thanks works beautifully
dudeqwerty
09-15-2009, 10:01 AM
No worries. Obviously the trace isn't needed.
I've also spotted a little error, changing:
colour1.toString(16):colour2.toString(16)
to
colour2.toString(16):colour1.toString(16)
will mean the first line's colour will be colour1.
flashkit.com
Copyright Internet.com Inc., All Rights Reserved.