O'Reilly logo

Actionscript Cookbook by Joey Lott

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

8.27. Responding to User Text Entry

Problem

You want to perform a task when the content of a text field is modified by user input.

Solution

Assign a function definition to the text field’s onChanged( ) event handler method. Alternatively, you can use a listener object with a defined onChanged( ) method and register it with the text field using addListener( ).

Discussion

You can specify actions to be performed each time the content of a text field is changed by user input, whether that change be deleting or cutting characters, typing in characters, or pasting characters. You can define the text field’s onChanged( ) event handler method:

myTextField.onChanged = function (  ) {
  trace("the value has been modified");
};

When a user makes any change to the value of an input text field with an onChanged( ) handler defined, the actions defined in the onChanged( ) handler are executed.

You can also define an onChanged( ) method for a listener object (or listener objects). If multiple objects need to be updated when a change occurs in the input text field’s value, you should register those objects as listeners. You should define an onChanged( ) method for the listener object and then register the listener with the text field’s addListener( ) method. The addListener( ) method takes a reference to the listener object. For example:

myListener = new Object(  );
myListener.onChanged = function (  ) {
  // Actions go here.
};
myTextField.addListener(myListener);

You can use addListener( ) to register as many ...

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