TextField.getNewTextFormat( ) Method

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
TextField.getNewTextFormat( ) Method Flash 6

retrieves the default TextFormat object for the text field
theField.getNewTextFormat()

Returns

A TextFormat object describing the default format for any characters added to theField.

Description

The getNewTextFormat( ) method returns a TextFormat object whose properties describe the format applied to any new characters added to theField. For a detailed description of TextFormat objects, see the TextFormat class.

Any text added to a field via TextField.text, TextField.replaceSel( ), or by the user is formatted according to the settings of the object returned by getNewTextFormat( ). For a new text field, the default TextFormat object has the property values shown in Table 18-25 under the Description heading for the TextFormat class entry.

The default values can be changed with setNewTextFormat( ). However, setNewTextFormat( ) does not format characters already in the field; it merely sets the format for any future characters that are added. To reformat characters already in a text field, use setTextFormat( ). To examine the format of characters already in a text field, use getTextFormat( ).

Usage

When the insertion point is placed in a text field by the user or with Selection.setSelection( ), the field's new text format is set to match the character to the insertion point's right (or left, in the case of the last character). The return value of getNewTextFormat( ) will reflect the format of that character. See the Example under TextField.setNewTextFormat( ) for code that forces the new text format not to adopt the existing text's format.

Example

The following code checks the default font size for a field named numbers_txt and then increases that size by ten points:

// Create a text field this.createTextField("numbers_txt", 1, 0, 0, 150, 40); // Assign the field some text to display numbers_txt.text = "one two three four"; // Retrieve the new text format object for numbers_txt var numbersNewTextFormat = numbers_txt.getNewTextFormat(); // Check the default font point size for new text trace(numbersNewTextFormat.size);  // Displays: 12 // Add ten points and apply the new default settings numbersNewTextFormat.size += 10; numbers_txt.setNewTextFormat(numbersNewTextFormat); // Now insert some text to see the change numbers_txt.text = "five six seven";

See Also

TextField.getTextFormat( ), TextField.setNewTextFormat( ), TextField.setTextFormat( ), the TextFormat class



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net