Using button and movie clip event handlers
337
Instead of using a listener object, as in the first procedure under
“Using event listeners with
components” on page 335
, you can use a custom function. The code in the previous example
could be rewritten as follows:
System.security.allowDomain("http://www.helpexamples.com");
my_ldr.addEventListener("progress", progressListener);
my_ldr.addEventListener("complete", completeListener);
my_ldr.load("http://www.helpexamples.com/flash/images/image1.png");
function progressListener(evt_obj:Object):Void {
trace(evt_obj.type); // progress
trace("\t" + evt_obj.target.bytes " of " +
evt_obj.target.byte " bytes loaded");
}
function completeListener(evt_obj:Object):Void {
trace(evt_obj.type); // complete
}
Using button and movie clip event
handlers
You can attach event handlers directly to a button or movie clip instance on the Stage by using
the
onClipEvent()
and
on()
event handlers. The
onClipEvent()
event handler broadcasts
movie clip events, and the
on()
event handler handles button events.
To attach an event handler to a button or movie clip instance, click the button or movie clip
instance on the Stage to bring it in focus, and then enter code in the Actions panel. The title
of the Actions panel reflects that code will be attached to the button or movie clip: Actions
Panel - Button or Actions Panel - Movie Clip. For guidelines about using code that’s attached
to button or movie clip instances, see
“Attaching code to objects” on page 746
.
NO
TE
In the previous examples, the event listeners are always added before the
Loader.load()
method is called. If you call the
Loader.load()
method before you
specify the event listeners, the load might complete before the event listeners are
fully defined. This means that the content might display and the
complete
event might
not be caught.
NO
T
E
Do not confuse button and movie clip event handlers with component events, such as
SimpleButton.click
,
UIObject.hide
, and
UIObject.reveal
, which must be
attached to component instances and are discussed in Using Components.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...