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:

my_fmt = new TextFormat();
my_fmt.bold = true;
my_txt.setTextFormat(my_fmt);

This code first creates an empty TextFormat object with all of its properties undefined, 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

Method

Description

TextFormat.getTextExtent()

Returns text measurement information for a text string.

Property summary for the TextFormat class

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.

TextFormat.indent

Indicates the indentation from the left margin to the first character in the paragraph.

TextFormat.italic

Indicates whether text is italicized.

TextFormat.leading

Indicates the amount of vertical space (called leading) between lines.

TextFormat.leftMargin

Indicates the left margin of the paragraph, in points.

TextFormat.rightMargin

Indicates the right margin of the paragraph, in points.

TextFormat.size

Indicates the point size of text.

TextFormat.tabStops

Specifies custom tab stops.

TextFormat.target

Indicates the window in a browser where a hyperlink is displayed.

TextFormat.underline

Indicates whether text is underlined.

TextFormat.url

Indicates the URL to which the text links.

Constructor for the TextFormat class

Availability

Flash Player 6.

Usage

new TextFormat([font, [size, [color, [bold, [italic, [underline, [url, [target, [align, [leftMargin, [rightMargin, [indent, [leading]]]]]]]]]]]]])

Parameters

font The name of a font for text as a string.

size An integer that indicates the point size.

color The color of text using this text format. A number containing three 8-bit RGB components; for example, 0xFF0000 is red, 0x00FF00 is green.

bold A Boolean value that indicates whether the text is boldface.

italic A Boolean value that indicates whether the text is italicized.

underline A Boolean value that indicates whether the text is underlined.

url The URL to which the text in this text format hyperlinks. If url is an empty string, the text does not have a hyperlink.

target The target window where the hyperlink is displayed. If the target window is an empty string, the text is displayed in the default target window _self. If the url parameter is set to an empty string or to the value null, you can get or set this property, but the property will have no effect.

align The alignment of the paragraph, represented as a string. If "left", the paragraph is left-aligned. If "center", the paragraph is centered. If "right", the paragraph is right-aligned.

leftMargin Indicates the left margin of the paragraph, in points.

rightMargin Indicates the right margin of the paragraph, in points.

indent An integer that indicates the indentation from the left margin to the first character in the paragraph.

leading A number that indicates the amount of leading vertical space between lines.

Returns

Nothing.

Description

Constructor; creates a TextFormat object with the specified properties. You can then change the properties of the TextFormat object to change the formatting of text fields.

Any parameter may be set to null to indicate that it is not defined. All of the parameters are optional; any omitted parameters are treated as null.