About the three methods of the button event processing [Learning Target]: Understand the three methods of the event handle, master the correct writing form of the ON function and the event function. On the previous tutorial we know the eight events on the button, which is commonly used. We will use specialized on keyboard operations to you with specialized keyboard operations. The first seven events for specific operations: Press, Release, Releaseoutside, Rollover, Rollout, Dragover, and Dragout. Understand the event, we can use these events to complete our control, let these events trigger the animation action we requested. Can those methods to complete? There are three ways, in which we use the first ON () function on our tutorial. Three methods for processing events are: 1 For the ON () event handler of the object. 2 Event processing function method. 3 event listener. Below we detailed introduction to the implementation of the button, the implementation of these three methods.
First, the ON () event handler ON () event handler on the button object is the most conventional event processing method. It acts directly on the button component instance, the related program code to write to the action script of the button instance. The general form of the ON () function is: ON (mouse event) {
/ / Here is your statement, the function of these statements, to respond to mouse events
} The "Mouse Event" called the "Mouse Event" called the "Mouse Event", which is the "eight events" we described above. Below we are doing an example: Requirements: The timeline of the main timeline and the movie clip is controlled by the button. Steps: 1. Creating a new Flash document, create 2 elements fang, yuan, draw a block on the component fang, drawing on the component yuan. 2, create a new component MOVE_MC, create motion animation with component YUAN, and add 2 Layer Move1_mc, Move2_mc in the first key plus AS: STOP (); 3. Drag into the component Fang on the layer Move1_mc, insert the key, create a motion animation at the 20th. Drop the component MOVE_MC on the layer MOVE2_MC and give this instance name: move_mc. 4, new layer ActionScript, in the first key plus AS: STOP (); 5, newly built 2 layers Move1_BTN, Move2_BTN, drag 2 buttons from the public library, laying Move1_BTN controls the main time Shaft, add as: on (press) {
Play ();
}
Layer Move2_BTN placed the timeline of the MOVE2_BTN Control Element YUAN, plus AS: ON (PRESS) {
Move_mc.play ();
}
Note: It is the key to see the two scripts above. So the script is placed on the ON function. The main problem is that the level of the object you control, and this problem will be introduced later. Example Effect Preview | Source Code Download II, Event Processing Function Method Event Process Process Method is a way to see it here, there is a new concept: class, there is nothing, do not understand jump. An event occurs when the instance of this class occurs. For example, the Button class defines the onpress event handler, as long as pressing the mouse, call the BUTTON object to call the processing function. Flash Player automatically invokes the event handler when the corresponding event occurs. By default, the event handler method is undefined: When a specific event occurs, its corresponding event handler is called, but the application does not respond to events. To let the application respond to the event, you need to use the function statement to define a function and assign the function to the corresponding event handler. Thus, as long as this event occurs, the function assigned to the event handler is automatically invoked. The event handler consists of three parts: the object applied by the event, the name of the object's event handler method, and the function of assigning the event handler. The basic structure of the event handler is: object. Event processing function method name = function () {// you have written program code, respond to events
} 1. The object applied to the event: It is an instance of a specific class. Here is our button, we will give it a name. 2, the name of the object's event handling function method: Simple, is a specific method. Then what is method, it is what you can do. For example, Wang Xiaomei is a sister. You can buy a car, you can go abroad ..., this Wang Xiaomei is an object, buying a car, going abroad, is a way, but if you let Ms. Wang go to a small egg is not Yes, because it doesn't have this method. The specific button you do is an object, it also has its own method, that is, the button can do. There is a "top ten functions", you understand the "eight events" introduced in front of us. Below I list this "Top Ten Functions":
Event Processing Function of the Button Class: Event Processing Function Description OnDragoutDragout When you press the mouse button on the button, then call the mouse pointer slide out the button. OnDragoverDragover When the user presses the mouse button outside the button and then drag the mouse pointer to the button above the button. ONKEYUPKEYPRESS Combined with the keyboard When the button is released, call OnkillFocus When the keyboard is removed from the button. When the button is removed, the mouse button is located above the button. When the mouse button is pressed, when the mouse button is located above the button, the mouse button is released. Time to call. OnReleaseOutsideReleaseOutside Press the button inside the button, then move the mouse pointer to the button and release the mouse button. OnrollOUTrollout calls ONROLLOVERROLLOVER when the mouse pointer is scrolled to the mouse pointer to the button. OnsetFocus is called when the button has input focus and releases a button. Is the content of the next section similar? It is more than 2 OnsetFocus, and OnkillFocus is useful in the keyboard operation. 3. Functions assigned to the event handle function This part is where we write code yourself. For the examples above, we will write according to the current method: Steps: 1. Create 2 elements Fang, Yuan, draw a block on the component fang, and draw a circle on the component Yuan. 2, create a new component MOVE_MC, create motion animation with component YUAN, and add 2 Layer Move1_mc, Move2_mc in the first key plus AS: STOP (); 3. Drag into the component Fang on the layer Move1_mc, insert the key, create a motion animation at the 20th. Drop the component MOVE_MC on the layer MOVE2_MC and give this instance name: move_mc. 4, create two layers Move1_BTN, Move2_BTN, drag 2 buttons from the public database, and put the button move1_btn on the layer MOVE1_BTN, and put the button move2_btn on the layer MOVE2_BTN. 5, new layer ActionScript, in the first key plus AS: stop (); Move1_btn.onpress = function () {
Play ();
}
Move2_btn.onpress = function () {
Move_mc.play ();
}
Is the effect? Is it easy to see? Just add AS :), the format can't remember, you can do it. Example Effect Preview | Source Code Download 3, Event Listener Event Listener A object (called listener object) receives an event generated by other objects (called broader objects). This details will be introduced in the future. Ok, today's content looks too much, in fact, think about it, just a new thing ... = function () ..., know this format you can die, icon button's top ten functions The name is more on the eight major events in front. Practice, look at the example, do it yourself.
Somewhere
http://jinjunshi.blogchina.com