ActionScript 2.0 Components Language Reference |
|
|
|
| TextInput component > Using the TextInput component > 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:true.
/**
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.
my_ti instance, you can get its value as follows:
var my_text:String = my_ti.text;
|
|
|
|