Learning ActionScript 2.0 in Adobe Flash |
|
|
|
| Handling Events > Using button and movie clip event handlers > 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");
}
|
NOTE |
Attaching |
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:
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);
The image loads into the img_mc instance, and the onPress() and onRelease() event handlers let you drag the image around the Stage.
|
|
|
|