Flash CS3 Documentation |
|||
| Programming ActionScript 3.0 > Working with text > Formatting text > Assigning text formats | |||
You can use the TextFormat class to set a number of different text display properties and to apply them to the entire contents of a TextField object, or to a range of text.
The following example applies one TextFormat object to an entire TextField object and applies a second TextFormat object to a range of text within that TextField object:
var tf:TextField = new TextField(); tf.text = "Hello Hello"; var format1:TextFormat = new TextFormat(); format1.color = 0xFF0000; var format2:TextFormat = new TextFormat(); format2.font = "Courier"; tf.setTextFormat(format1); var startRange:uint = 6; tf.setTextFormat(format2, startRange); addChild(tf);
The TextField.setTextFormat() method only affects text that is already displayed in the text field. If the content in the TextField changes, your application might need to call the TextField.setTextFormat() method again to reapply the formatting. You can also set the TextField object's defaultTextFormat property to specify the format to be used for user-entered text.
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00000230.html