The listener-broadcaster model for events, unlike event handler methods, lets you have
multiple pieces of code listen to the same event without conflict. Event models that do not use
the listener/broadcaster model, such as
pieces of code are listening to the same event; the different pieces of code have conflicts over
control of that single
model, you can easily add listeners to the same event without worrying about code
bottlenecks.
The following ActionScript classes can broadcast events: Key, Mouse,
MovieClipLoader, Selection, Stage, and TextField. To see which
listeners are available for a class, see each class entry in the ActionScript 2.0 Language Reference.
For more information on event listeners, see the following topics:
"Event listener model" on page 333
"Event listener example" on page 334
The Stage class can broadcast events. You can find a sample source file, stagesize.fla, in the
Samples folder on your hard disk. This sample demonstrates how the
property affects the values of
is resized.
In Windows, browse to boot drive\Program Files\Macromedia\Flash 8\Samples and
Tutorials\Samples\ActionScript\StageSize.
On the Macintosh, browse to Macintosh HD/Applications/Macromedia Flash 8/Samples
and Tutorials/Samples/ActionScript/StageSize.
Event listener model
The event model for event listeners is similar to the model for event handlers (see
event handler methods" on page
You assign the event handler to the listener object, not the object that broadcasts
the event.
You call a special method of the broadcaster object,
listener object to receive its events.
The following code outlines the event listener model:
var listenerObject:Object = new Object();
listenerObject.eventName = function(eventObj:Object) {
// Your code here
};
broadcasterObject.addListener(listenerObject);
XML.onLoad()
callback function reference. With the listener/broadcaster
XML.onLoad
Stage.width
330), with two main differences:
, can be problematic when various
and
when the browser window
Stage.height
addListener()
Stage.scaleMode
"Using
, which registers the
Using event listeners
333
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?