User Guide
Using the TextInput component 1211
Creating an application with the TextInput component
The following procedure explains how to add a TextInput component to an application while
authoring. In this example, the component is a password field with an event listener that
determines if the proper number of characters has been entered.
To create an application with the TextInput component:
1. Drag a TextInput component from the Components panel to the Stage.
2. In the Property inspector, do the following:
■ Enter the instance name my_ti.
■ Leave the text parameter blank.
■ Set the editable parameter to true.
3. Select Frame 1 in the Timeline, open the Actions panel, and enter the following code:
/**
Requires:
- TextInput instance on Stage (instance name: my_ti)
*/
var my_ti:mx.controls.TextInput;
// Create listener object.
var tiListener:Object = new Object();
tiListener.handleEvent = function (evt_obj:Object){
if (evt_obj.type == "enter"){
if (my_ti.length < 8) {
trace("You must enter at least 8 characters");
} else {
trace("Thanks");
}
}
}
// Add listener.
my_ti.addEventListener("enter", tiListener);
This code sets up an enter event handler on the TextInput instance called my_ti. If the
user types less than eight characters, the example displays the message:
You must enter
at least 8 characters
. If the user enters eight or more characters, the example
displays:
Thanks.
4. After text is entered in the my_ti instance, you can get its value as follows:
var my_text:String = my_ti.text;