A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] alternate text colors.

  1. #1
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588

    resolved [RESOLVED] alternate text colors.

    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.
    ~calmchess~

  2. #2
    Senior Member dudeqwerty's Avatar
    Join Date
    Mar 2005
    Location
    Bosnia
    Posts
    1,626
    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);
    New sig soon

  3. #3
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    thanks works beautifully
    ~calmchess~

  4. #4
    Senior Member dudeqwerty's Avatar
    Join Date
    Mar 2005
    Location
    Bosnia
    Posts
    1,626
    No worries. Obviously the trace isn't needed.

    I've also spotted a little error, changing:
    Code:
    colour1.toString(16):colour2.toString(16)
    to
    Code:
    colour2.toString(16):colour1.toString(16)
    will mean the first line's colour will be colour1.
    New sig soon

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center