Skip to main content
Participant
July 26, 2006
Question

Dynamic txtfields

  • July 26, 2006
  • 1 reply
  • 155 views
Hi all,

I was wonder how i can change the color of the third charachter in a dynamic textfield, which gets its content from an external txt file. --> all text have this structure: "03: nameoftile". i want the : in a different colour!!

Hope anyone can help me thx!!!!

V
This topic has been closed for replies.

1 reply

Known Participant
July 26, 2006
First you will have to define a textFormat object. You can do this using the textFormat contructor and describing the properties you want to add. For example:

var myTxtFormat = new TextFormat();
myTxtFormat.color = #0xff0000;

Then after you set up your textFormat object, you just apply that to your text field. Like this:

TextField.setTextFormat(2, myTxtFormat);

TextField will be the name of the dynamic text field you have set up and the number 2 is the index of the character that you want to apply the textFormat to. If you want to apply the txtFormat to a span of characters in your text field you can use this syntax:

TextField.setTextFormat(2, 10, myTxtFormat);

or you can apply it to the entire text field like this:

TextField.setTextFormat(myTxtFormat);


There are a lot of other format options that you can add to the textFormat class. Consult your help files in Flash for a list of the possible properties. Here are just a few samples:

textFormat.align
textFormat.bold
textFormat.color
textFormat.font
textFormat.indent
textFormat.italic
textFormat.underline