Using button and movie clip event handlers
341
Attaching or assigning multiple handlers to one object
You can also attach more than one handler to an object if you want different scripts to run
when different events occur. For example, you could attach the following
onClipEvent()
handlers to the same movie clip instance. The first executes when the movie clip first loads (or
appears on the Stage); the second executes when the movie clip is unloaded from the Stage.
on (press) {
this.unloadMovie()
}
onClipEvent (load) {
trace("I've loaded");
}
onClipEvent (unload) {
trace("I've unloaded");
}
To attach multiple handlers to one object using code that’s placed on the timeline, see the
following example. The code attaches the
onPress
and
onRelease
handlers to a movie clip
instance.
To assign multiple handlers to an object:
1.
Create a new Flash document, and name it
assignMulti.fla
.
2.
Select Frame 1 of the Timeline, and add the following code in the Actions panel:
this.createEmptyMovieClip("img_mc", 10);
var mclListener:Object = new Object();
mclListener.onLoadInit = function(target_mc:MovieClip) {
target_mc.onPress = function() {
target_mc.startDrag();
};
target_mc.onRelease = function() {
target_mc.stopDrag();
};
}
mclListener.onLoadError = function(target_mc:MovieClip) {
trace("error downloading image");
}
var img_mcl:MovieClipLoader = new MovieClipLoader();
img_mcl.addListener(mclListener);
img_mcl.loadClip("http://www.helpexamples.com/flash/images/image1.jpg",
img_mc);
NO
TE
Attaching
onClipEvent()
and
on()
handlers is not a recommended practice. Instead, you
should put your code in frame scripts or in a class file, as demonstrated throughout this
manual. For more information, see
“Using event handler methods” on page 330
and
“Attaching code to objects” on page 746
.
Содержание 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...