TextField.text Property

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
TextField.text Property Flash 6

specifies the characters to be rendered in the field read/write
theField.text

Description

The string text property specifies the characters displayed by theField. Assigning a value to the text property causes characters to display in theField. Retrieving the text property tells us the entire textual content of theField, including any user input. When text cannot fit in theField's rectangular bounding box, the excess wraps to the next line or overflows theField, or theField's bounding box is resized, depending on the settings of autoSize, multiline, and wordWrap. Any text overflow must be viewed through horizontal or vertical scrolling (see hscroll and scroll).

Text can be formatted via the setTextFormat( ) and setNewTextFormat( ) methods. However, reassigning the text property clears all previous formatting. To add text to a field without disturbing any existing formatting, use replaceSel( ).

See TextField.htmlText for a full discussion of assigning HTML-formatted text to a text field. Take heed that htmlText and text overwrite each other. Regardless of the value of the html property, assigning a value to text overwrites the value of htmlText, and vice versa.

Usage

In Flash 4 and Flash 5, text fields were represented by simple variables, not complete objects. Hence, it was common to assign text directly to a text field variable, as follows:

theField_txt = "Welcome to my site.";

As of Flash 6, this practice will erroneously overwrite the TextField instance. The correct syntax in Flash 6 is as follows:

theField_txt.text = "Welcome to my site.";

See TextField.variable for details.

Example

The text property is our main means of programmatically displaying text on screen. It's Flash's best candidate for a "hello world" example, as follows:

// Create a text field this.createTextField("theField_txt", 1, 0, 0, 200, 20); // Drum roll please... theField_txt.text = "hello world!";

The following code echoes the value of an input text field to the Output window every 500 milliseconds. Export it in Test Movie mode and type into the text field.

this.createTextField("theField_txt", 1, 0, 0, 200, 20); theField_txt.type = "input"; theField_txt.border = true; setInterval(showInput, 500); function showInput () {   trace(theField_txt.text); }

See Also

The Selection object, TextField.html, TextField.htmlText, TextField.replaceSel( ), TextField.variable



    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