User Guide

TextField.setTextFormat() 919
Notice that any text inserted manually by the user, or replaced by means of TextField.replaceSel(),
receives the text field's default formatting for new text, and not the formatting specified for the
text insertion point. To set a text field’s default formatting for new text, use
Te xt Fi el d . se t Ne w Te xt Fo r ma t( ) .
Example
The following example sets the text format for two different strings of text. The setTextFormat()
method is called and applied to the
my_txt text field.
var format1_fmt:TextFormat = new TextFormat();
format1_fmt.font = "Arial";
var format2_fmt:TextFormat = new TextFormat();
format2_fmt.font = "Courier";
var string1:String = "Sample string number one."+newline;
var string2:String = "Sample string number two."+newline;
this.createTextField("my_txt", this.getNextHighestDepth(), 0, 0, 300, 200);
my_txt.multiline = true;
my_txt.wordWrap = true;
my_txt.text = string1;
var firstIndex:Number = my_txt.length;
my_txt.text += string2;
var secondIndex:Number = my_txt.length;
my_txt.setTextFormat(0, firstIndex, format1_fmt);
my_txt.setTextFormat(firstIndex, secondIndex, format2_fmt);
See also
Te xt Fi el d . se t Ne w Te xt Fo r ma t( ) , TextFormat class