Apply textformat to input text 3
Today I encountered a weird little problem.
I created an input textfield with actionscript and wanted to apply a textformat to it.
The following code created the desired textfield:
this.createTextField(“name_txt”, this.getNextHighestDepth(), 10, 20, this._width – 20, 15);
this.name_txt.border = true;
this.name_txt.borderColor = color1;
this.name_txt.text = “Name”;
this.name_txt.type = “input”;
this.name_txt.maxChars = 20;
Textformat:
//——————————
// SET TEXTFORMAT
// – color -> color of the text
// – align -> “left”, “center” or “right” (“justify” in flash 8 )
// – bold -> true or false
//——————————
public function setTextFormatOptions(color:Number, align:String, bold:Boolean):Void {
my_fmt = new TextFormat();
my_fmt.font = “Verdana”;
my_fmt.color = color;
my_fmt.align = align;
my_fmt.size = 10;
my_fmt.bold = bold;
}
To set and apply this textformat:
setTextFormatOptions(0×999999, “left”, true);
this.name_txt.setTextFormat(my_fmt);
Now, this worked perfectly for the text that I put into the textfield initially, so by code … but as soon as I started inputting my own text, the textformat was gone …
Now, what’s the solution, just put this line under it:
this.name_txt.setNewTextFormat(my_fmt);
And all the text you input in the field will look like the textformat too.
To sum it up, the setTextFormat seems to be only for text that is hard coded into the textfield and the setNewTextFormat property seems to be only for the new user inputted text. So if you want to put both an initial text in the textfield and being able to have user input in that textfield, you have to put both lines in your code …








Feb 27, 2007 @ 21:04:20
I had the same problem, thanks to you I was able to solve it!
Mar 03, 2007 @ 18:08:19
Thought it was interesting to make a note of. Glad it could help you
Jul 03, 2009 @ 16:17:52
wow….