The code starts with an object,
object can be any object, such as an existing object, movie clip, or button instance on the
Stage, or it can be an instance of any ActionScript class. For example, a custom movie clip
could implement the listener methods for Stage listeners. You could even have one object that
listens to several types of listeners.
The
property is an event that occurs on
eventName
broadcasts the event to
event broadcaster.
You assign a function to the event listener that responds to the event in some way.
Last, you call the
addListener()
object to the addListener() method.
To unregister a listener object from receiving events, you call the
method of the broadcaster object, passing it the name of the event to remove, and the
listener object.
broadcasterObject.removeListener(listenerObject);
Event listener example
The following example shows how to use the
to create a simple focus manager for a group of input text fields. In this case, the border of the
text field that receives keyboard focus is enabled (appears), and the border of the text field that
does not have focus is disabled.
To create a simple focus manager with event listeners:
1.
Using the Text tool, create a text field on the Stage.
2.
Select the text field, and then in the Property inspector, select Input from the Text Type
pop-up menu and select the Show Border Around Text option.
3.
Create another input text field below the first one.
Make sure the Show Border Around Text option is not selected for this text field. You can
continue to create input text fields.
4.
Select Frame 1 in the Timeline and open the Actions panel (Window > Actions).
334
Handling Events
listenerObject
. You can register multiple listeners to one
listenerObject
method on the broadcaster object, passing the listener
, with a property
broadcasterObject
removeEventListener()
event listener in the Selection class
onSetFocus
. Your listener
eventName
, which then
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?
Questions and answers