TextField.type Property

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

specifies whether the field can accept user input read/write
theField.type

Description

The string type property determines a field's input and output behavior. It has only two possible values: "input" and "dynamic" (the default). A dynamic text field is used to display information to the user (output only); an input text field can retrieve information from the user (input and output).

The Flash 5 Multiline and Password settings for a text field are represented by the multiline and password properties, not by type.

When type is set to "input", the user can enter text into the field and we can examine the input via its text property (see TextField.text for a code sample). When type is set to "dynamic", the user cannot type into the field. However, characters can still be selected unless selectable is set to false explicitly. Unicode text can be entered into input text fields when Unicode is supported by the operating system.

Because data entered by the user into an input text field is always a string, we should convert it explicitly before using it in a nonstring context, as demonstrated in this simple calculator example that totals two user-input text fields:

// Suppose myFirstInput is 5, mySecondInput is 10, and we total the fields. // WRONG: "Adding" the fields together sets myOutput to "Total: 510" // because the + operator is interpreted as a string concatenator. myOutput.text = "Total: " + (myFirstInput.text + mySecondInput.text); // RIGHT: First, convert the fields to numbers in order to get the right result. myOutput.text = "Total: " + (parseFloat(myFirstInput.text)                           + parseFloat(mySecondInput.text));

Example

The following example creates a title that can neither be selected nor receive input:

this.createTextField("title_txt", 1, 0, 0, 200, 20); title_txt.selectable = false; title_txt.type = "dynamic"; title_txt.text = "Tea Brewing Around the World";

The following example creates an input field to allow a user to enter a name. It's customary to add a border to input text fields via the border property. This adds a visual cue indicating the field is editable:

this.createTextField("firstName_txt", 1, 0, 0, 200, 20); firstName_txt.type = "input"; firstName_txt.border = true;

See Also

parseFloat( ), TextField.border, TextField.multiline, TextField.password, TextField.restrict, TextField.selectable, TextField.text



    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