Say the usual events, in terms of two different ways of dealing with events. The event-handling code described earlier is added like this: First, select the object that will capture the event (the movie clip instance or button), and then open the script panel and write the "on event name" code. For example, if we want a movie clip instance to capture the MouseDown event, you can select the movie clip instance in the scene first (assuming its name is MOVIECLIP_MC), and then set the code such as the following.
Onclipevent (MouseDown) {
}
This method is simple and intuitive to use, but it has one drawback: lack of interactivity. What do you say? The event-handling code established by this method is "fixed" and cannot be dynamically changed during the running of the program. Let's say we want this movie clip to use a piece of code to handle the MouseDown event when the movie plays to frame 10th, but when the movie plays to frame 20th, we need another piece of code to handle the MouseDown event. This application you have not encountered, to give an intuitive example that we have used the TV remote control, the TV remote control many buttons are "multimode", that is, these buttons in different states function is different. The button that adjusts the sound is used to increase and decrease the volume in the normal state, but if you enter the color setting mode, the same button is not the volume but the color.
Still take the example above to illustrate that if we add such code to a frame of the movie
Movieclip_mc.onmousedown = function () {
}
You can implement a dynamic switch to the event handling code. This statement is special, which means that the OnMouseDown event handling code for the movie clip instance MOVIECLIP_MC is replaced with a function (), and the curly brace behind the function () is the new event-handling code. You can use this method more than once in a movie, so that the dynamic adjustment of the event-handling generation can be achieved as long as the contents of the function () functions are different at a later time. To be aware, using this method to define the event handling code is that the movie clip instance must appear in the scene, and when it disappears from the scene, the event-handling code is automatically deleted and, if used again, must be specified again. If you want to delete the processing code for the time, you can use a statement such as delete Movieclip_mc.onmousedown.
Often when writing more complex programs, we tend to use event handlers to set up event-handling code for objects in the scene, because this allows the most code to be strung together through an event line to facilitate code maintenance and debugging. Otherwise, the code scattered inside the object, easy to make the code more confusing, out of the problem is not easy to find the wrong place.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.