Flash CS3 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript classes > TextFormat | |||
Object
|
+-TextFormat
public class TextFormat
extends Object
The TextFormat class represents character formatting information. Use the TextFormat class to create specific text formatting for text fields. You can apply text formatting to both static and dynamic text fields. The properties of the TextFormat class apply to device and embedded fonts. However, for embedded fonts, bold and italic text actually require specific fonts. If you want to display bold or italic text with an embedded font, you need to embed the bold and italic variations of that font.
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() or TextField.setNewTextFormat(), only its defined properties are applied. Use setNewTextFormat() to apply formatting BEFORE you add text to the TextField, and setTextFormat() to add formatting AFTER you add text to the TextField, as in the following examples:
this.createTextField("my_txt", this.getNextHighestDepth(), 0, 0, 100, 22);
my_txt.autoSize = true;
var my_fmt:TextFormat = new TextFormat();
my_fmt.bold = true;
my_txt.setNewTextFormat(my_fmt);
my_txt.text = "Lorem ipsum dolor sit amet...";
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 MovieClip.getNextHighestDepth() method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components' DepthManager class instead of the MovieClip.getNextHighestDepth() method.
The methods my_txt.setNewTextFormat(my_fmt) and my_txt.setTextFormat(my_fmt) in these examples only change 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.
Availability: ActionScript 1.0; Flash Player 6
setNewTextFormat (TextField.setNewTextFormat method), setTextFormat (TextField.setTextFormat method), getTextFormat (TextField.getTextFormat method)
|
Modifiers |
Property |
Description |
|---|---|---|
|
|
A string that indicates the alignment of the paragraph. |
|
|
|
A number that indicates the block indentation in points. |
|
|
|
A Boolean value that specifies whether the text is boldface. |
|
|
|
A Boolean value that indicates that the text is part of a bulleted list. |
|
|
|
Indicates the color of text. |
|
|
|
The name of the font for text in this text format, as a string. |
|
|
|
An integer that indicates the indentation from the left margin to the first character in the paragraph. |
|
|
|
A Boolean value that indicates whether text in this text format is italicized. |
|
|
|
A Boolean value that indicates whether kerning is enabled or disabled. |
|
|
|
An integer that represents the amount of vertical space in pixels (called leading) between lines. |
|
|
|
The left margin of the paragraph, in points. |
|
|
|
The amount of space that is uniformly distributed between characters. |
|
|
|
The right margin of the paragraph, in points. |
|
|
|
The point size of text in this text format. |
|
|
|
Specifies custom tab stops as an array of non-negative integers. |
|
|
|
Indicates the target window where the hyperlink is displayed. |
|
|
|
A Boolean value that indicates whether the text that uses this text format is underlined ( |
|
|
|
Indicates the URL that text in this text format hyperlinks to. |
Properties inherited from class Object constructor (Object.constructor property), __proto__ (Object.__proto__ property), prototype (Object.prototype property), __resolve (Object.__resolve property)
|
Signature |
Description |
|---|---|
|
TextFormat |
Creates a TextFormat object with the specified properties. |
|
Modifiers |
Signature |
Description |
|---|---|---|
|
|
getTextExtent |
Returns text measurement information for the text string |
Methods inherited from class Object
Flash CS3