![]() ![]() ![]() | |
![]() | |
![]() | |
![]() |
You can use the ActionScript TextFormat class to set 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()
methods.
The setTextFormat()
method changes the text format applied to individual characters, to groups of characters, or to the entire body of text in a text field. Newly inserted text, howeversuch as that entered by a user or inserted with ActionScriptdoes 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 TextField.setTextFormat()
and TextField.setNewTextFormat()
.
myText_txt
in the Instance Name text box, select Dynamic from the Text Type pop-up menu, and select Multiline from the Line Type pop-up menu.bold
and italic
properties to true
, and its size
property to 24.
// Create a TextFormat object var txtfmt_fmt = new TextFormat(); // Specify paragraph and character formatting txtfmt_fmt.bold = "true"; txtfmt_fmt.italic = "true"; txtfmt_fmt.size = "24"
TextField.setTextFormat()
.
myText_txt
.setTextFormat(txtfmt_fmt);
This version of setTextFormat()
applies the specified formatting to the entire text field. There are two other versions of this method that 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 four characters you entered in the text field.
myText_txt
.setTextFormat(txtfmt_fmt, 0, 3);
For more information, see TextField.setTextFormat()
.
![]() | |
![]() | |
![]() | |
![]() ![]() ![]() |