Flash CS3 Documentation |
|||
| Learning ActionScript 2.0 in Adobe Flash > Working with Text and Strings > About text layout and formatting > Using the TextFormat class | |||
You can use the TextFormat class to set the formatting properties of a text field. The TextFormat class incorporates character and paragraph formatting information. Character formatting information describes the appearance of individual characters: font name, point size, color, and an associated URL. Paragraph formatting information describes the appearance of a paragraph: left margin, right margin, indentation of the first line, and left, right, or center alignment.
To use the TextFormat class, you first create a TextFormat object and set its character and paragraph formatting styles. You then apply the TextFormat object to a text field using the TextField.setTextFormat() or TextField.setNewTextFormat() method.
The setTextFormat() method changes the text format that is applied to individual characters, to groups of characters, or to the entire body of text in a text field. Newly inserted text, however--such as text entered by a user or inserted with ActionScript--does not assume the formatting specified by a setTextFormat() call. To specify the default formatting for newly inserted text, use TextField.setNewTextFormat(). For more information, see setTextFormat (TextField.setTextFormat method) and setNewTextFormat (TextField.setNewTextFormat method) in the ActionScript 2.0 Language Reference.
Type some text in the text field on the Stage, such as Bold, italic, 24 point text.
bold and italic properties to true, and set the size property to 24:// Create a TextFormat object. var txt_fmt:TextFormat = new TextFormat(); // Specify paragraph and character formatting. txt_fmt.bold = true; txt_fmt.italic = true; txt_fmt.size = 24;
TextField.setTextFormat():
myText_txt.setTextFormat(txt_fmt);
This version of setTextFormat() applies the specified formatting to the entire text field. Two other versions of this method let you apply formatting to individual characters or groups of characters. For example, the following code applies bold, italic, 24-point formatting to the first three characters you entered in the text field:
myText_txt.setTextFormat(0, 3, txt_fmt);
For more information, see setTextFormat (TextField.setTextFormat method) in the ActionScript 2.0 Language Reference.
For more information on using the TextFormat class, see the following topics:
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/00000905.html