O'Reilly logo

Essential ActionScript 3.0 by Colin Moock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Text Field Input

Text fields can receive a variety of forms of user input, including text entry, text selection, hypertext-link activation, keyboard focus, scrolling, and mouse interaction. In this section, we'll study text entry, text selection, and hypertext links. For information on keyboard focus, scrolling, and mouse interaction, see Chapter 22.

Text Entry

Each text field's ability to receive user input is governed by the value of its type variable. By default, for text fields created with ActionScript, the instance variable type is set to TextFieldType.DYNAMIC, meaning that text can be modified through ActionScript but not by the user. To allow a text field to receive user input, we must set type to TextFieldType.INPUT, as shown in the following code:

var t:TextField = new TextField();
t.type = TextFieldType.INPUT;

When a TextField object's type variable is set to TextFieldType.INPUT, the user can add text to or delete text from the text field. The user's modifications are automatically reflected by the text and htmlText variables.

To be notified when a text field's text is modified by the user, we can register with that text field for TextEvent.TEXT_INPUT and Event.CHANGE events. The TextEvent.TEXT_INPUT event is dispatched when the user attempts to change the text of the text field, before the text and htmlText variables are updated. The Event.CHANGE event is dispatched after the text and htmlText variables have been updated in response to user input. For complete details on ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required