03.05.2013 Views

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

addListener (Selection.addListener method)<br />

public static addListener(listener:Object) : Void<br />

Registers an object to receive keyboard focus change notifications. When the focus changes<br />

(for example, whenever Selection.setFocus() is invoked), all listening objects registered<br />

with addListener() have their onSetFocus method invoked. Multiple objects may listen for<br />

focus change notifications. If the specified listener is already registered, no change occurs.<br />

Availability: <strong>ActionScript</strong> 1.0; Flash Player 6<br />

Parameters<br />

listener:Object - A new object with an onSetFocus method.<br />

Example<br />

In the following example, you create two input text fields at runtime, setting the borders for<br />

each text field to true. This code creates a new (generic) <strong>ActionScript</strong> object named<br />

focusListener. This object defines for itself an onSetFocus property, to which it assigns a<br />

function. The function takes two parameters: a reference to the text field that lost focus, <strong>and</strong><br />

one to the text field that gained focus. The function sets the border property of the text field<br />

that lost focus to false, <strong>and</strong> sets the border property of the text field that gained focus to<br />

true:<br />

this.createTextField("one_txt", 99, 10, 10, 200, 20);<br />

this.createTextField("two_txt", 100, 10, 50, 200, 20);<br />

one_txt.border = true;<br />

one_txt.type = "input";<br />

two_txt.border = true;<br />

two_txt.type = "input";<br />

var focusListener:Object = new Object();<br />

focusListener.onSetFocus = function(oldFocus_txt, newFocus_txt) {<br />

oldFocus_txt.border = false;<br />

newFocus_txt.border = true;<br />

};<br />

Selection.addListener(focusListener);<br />

When you test the SWF file, try using Tab to move between the two text fields. Make sure<br />

that you select Control > Disable Keyboard Shortcuts so you can change focus between the<br />

two fields using Tab.<br />

See also<br />

setFocus (Selection.setFocus method)<br />

Selection 1085

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!