Working with Text and HTML in Flash - Using TextFormat Class
(Page 3 of 6 )
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 that is applied to individual characters, to groups of characters, or to the entire body of text in a text field. The text that is newly inserted, such as text entered by a user or inserted with ActionScript, does not assume the formatting specified by a setTextFormat() methodcall. To specify the default formatting for newly inserted text you need to use the setNewTextFormat() method.
Now let's see an example of how to use the TextFormat class.
// Create a TextFormat object
var txtfmt:TextFormat = new TextFormat();
// Specify paragraph and character formatting
txtfmt.bold = true;
txtfmt.italic = true;
txtfmt.underline = true;
txtfmt.bullet = false;
txtfmt.align = “center”;
txtfmt.color = “0xFF0000”;
txtfmt.font = “Verdana”;
txtfmt.url = “http://www.devarticles.com”;
txtfmt.target = “_blank”;
txtfmt.indent = 10;
txtfmt.size = 24;
// apply the TextFormat object to the text field
sample _txt.setTextFormat(txtfmt);
You can also apply the TextFormat object properties to a specific part of the text field as shown below.
// applies the TextFormat object only to the first three characters of the text field
sample_txt.setTextFormat(0, 3, txtfmt);
You can also apply the TextFormat object properties to a specific character of the text field as shown below.
// applies the TextFormat object only to the second character of the text field
sample_txt.setTextFormat(3, txtfmt);
Next: Formatting Text using HTML >>
More Flash Articles
More By Adi Reddy Mora