The following figure illustrates these measurements.
When setting up your TextFormat object, set all the attributes exactly as they will be set for the
creation of the text field, including font name, font size, and leading. The default value for
leading is 2.
Example
This example creates a single-line text field that's just big enough to display a text string using the
specified formatting.
var my_str:String = "Small string";
// Create a TextFormat object,
// and apply its properties.
var my_fmt:TextFormat = new TextFormat();
with (my_fmt) {
font = "Arial";
bold = true;
}
// Obtain metrics information for the text string
// with the specified formatting.
var metrics:Object = my_fmt.getTextExtent(my_str);
// Create a text field just large enough to display the text.
this.createTextField("my_txt", this.getNextHighestDepth(), 100, 100,
metrics.textFieldWidth, metrics.textFieldHeight);
my_txt.border = true;
my_txt.wordWrap = true;
// Assign the same text string and TextFormat object to the my_txt object.
my_txt.text = my_str;
my_txt.setTextFormat(my_fmt);
The following example creates a multiline, 100-pixel-wide text field that's high enough to display
a string with the specified formatting.
952
Chapter 2: ActionScript Language Reference
Need help?
Do you have a question about the FLASH MX 2004-ACTIONSCRIPT LANGUAGE and is the answer not in the manual?
Questions and answers