User Guide

776 Chapter 7: ActionScript for Flash
TextFormat class
Availability
Flash Player 6.
Description
The TextFormat class represents character formatting information.
You must use the constructor
new TextFormat() to create a TextFormat object before calling
its methods.
You can set TextFormat parameters to
null to indicate that they are undefined. When you apply
a TextFormat object to a text field using
TextField.setTextFormat(), only its defined
properties are applied, as in the following example:
this.createTextField("my_txt", this.getNextHighestDepth(), 0, 0, 100, 22);
my_txt.autoSize = true;
my_txt.text = "Lorem ipsum dolor sit amet...";
var my_fmt:TextFormat = new TextFormat();
my_fmt.bold = true;
my_txt.setTextFormat(my_fmt);
This code first creates an empty TextFormat object with all of its properties null, and then sets
the
bold property to a defined value.
The code
my_txt.setTextFormat(my_fmt) only changes the bold property of the text field’s
default text format, because the
bold property is the only one defined in my_fmt. All other aspects
of the text field’s default text format remain unchanged.
When
TextField.getTextFormat() is invoked, a TextFormat object is returned with all of its
properties defined; no property is
null.
Method summary for the TextFormat class
Property summary for the TextFormat class
Method Description
TextFormat.getTextExtent()
Returns text measurement information for a text string.
Property Description
TextFormat.align
Indicates the alignment of a paragraph.
TextFormat.blockIndent
Indicates the block indentation, in points.
TextFormat.bold
Indicates whether text is boldface.
TextFormat.bullet
Indicates whether text is in a bulleted list.
TextFormat.color
Indicates the color of text.
TextFormat.font
Indicates the font name of the text with a text format.
CHAPTER 7
ActionScript for Flash