Learning ActionScript 2.0 in Adobe Flash |
|
|
|
| Handling Events > Using button and movie clip event handlers > Using on and onClipEvent with event handler methods | |||
You can, in some cases, use different techniques to handle events without conflict. Using the on() and onClipEvent() methods doesn't conflict with using event handler methods that you define.
For example, suppose you have a button in a SWF file; the button can have an on(press) handler that tells the SWF file to play, and the same button can have an onPress() method, for which you define a function that tells an object on the Stage to rotate. When you click the button, the SWF file plays and the object rotates. Depending on when and what kinds of events you want to invoke, you can use the on() and onClipEvent() methods, event handler methods, or both techniques of event handling.
However, the scope of variables and objects in on() and onClipEvent() handlers is different than in event handler and event listeners. See Event handler scope.
You can also use on() with movie clips to create movie clips that receive button events. For more information, see Creating movie clips with button states. For information on specifying events for on() and onClipEvent(), see Specifying events for on or onClipEvent methods.
To use an on handler and onPress event handler:
on (press) {
trace("on (press) {...}");
}
box_mc.onPress = function() {
trace("box_mc.onPress = function() {...};");
};
When you click the movie clip symbol on the Stage, the following output is sent to the Output panel:
on (press) {...}
box_mc.onPress = function() {...};
|
NOTE |
Attaching |
|
|
|
|