public addListener(listener:Object) : Boolean
Registers an object to receive TextField event notifications. The object will receive event notifications whenever 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.The parameter is then used in a trace() method to write the instance name of the text field to the log file.
my_txt.onScroller = function(textfield_txt:TextField) {
trace(textfield_txt._name+" scrolled");
};
listener:Object - An object with an onChanged or onScroller event handler.
Boolean -
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_(xt: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");
};
my_txt.addListener(txtListener);
onChanged (TextField.onChanged handler), onScroller (TextField.onScroller handler), removeListener (TextField.removeListener method)