User Guide
TextField.addListener() 873
TextField.addListener()
Availability
Flash Player 6.
Usage
my_txt.addListener(listener:Object) : Void
Parameters
listener
An object with an onChanged or onScroller event handler.
Returns
Nothing.
Description
Method; registers an object to receive notification when the onChanged and onScroller event
handlers have been invoked. When a text field changes or is scrolled, the
TextField.onChanged
and
TextField.onScroller event handlers are invoked, followed by the onChanged and
onScroller event handlers of any objects registered as listeners. Multiple objects can be
registered as listeners.
To remove a listener object from a text field, call
TextField.removeListener().
A reference to the text field instance is passed as a parameter to the
onScroller and onChanged
handlers by the event source. You can capture this data by putting a parameter in the event
handler method. For example, the following code uses
txt as the parameter that is passed to the
onScroller event handler. The parameter is then used in a trace statement to send the instance
name of the text field to the Output panel.
my_txt.onScroller = function(textfield_txt:TextField) {
trace(textfield_txt._name+" scrolled");
};
Example
The following example defines an onChanged handler for the input text field my_txt. It then
defines a new listener object,
txtListener, and defines an onChanged handler for that object.
This handler will be invoked when the text field
my_txt is changed. The final line of code calls
TextField.addListener to register the listener object txtListener with the text field my_txt
so that it will be notified when
my_txt changes.
this.createTextField("my_txt", this.getNextHighestDepth(), 10, 10, 100, 22);
my_txt.border = true;
my_txt.type = "input";
my_txt.onChanged = function(textfield_txt:TextField) {
trace(textfield_txt._name+" changed");
};
var txtListener:Object = new Object();
txtListener.onChanged = function(textfield_txt:TextField) {
trace(textfield_txt._name+" changed and notified myListener");