Mouse | Response we all know that Flash animation can respond to mouse movements, so as to achieve a wide range of human-computer interaction. Commonly used mice have the left and right three keys.
1. Left key
The left mouse button in the Windows system under the responsibility of the sacred, in Flash is no exception. Flash can automatically capture the left mouse button action, and based on the captured action to fire the built-in mouse events, and then based on the user for these events written processing function to complete the left mouse button response.
Buttons and movie clips are often used to complete the process of responding to the mouse and implementing interactions. For buttons, you can respond to the left arrow action with the event handler function defined on the keyword on. Where press represents the left-click event, release indicates the left-key event, and Releaseoutside represents the event to release the left arrow outside the button, and so on. For example, to make a button respond to a click event, you can add the following code to the button's action panel:
On (release) {
Trace ("clicked");
}
This way, when you click the button in the test state, Flash sends the information "clicked" to the Output window.
For movie clips, you can also add an on event handler function that responds to the left mouse button as a mechanism for the buttons. Alternatively, you can respond to the left mouse button with the Onclipevent event handler function that is unique to the movie clip. For example, MouseDown represents the left-click event, and MouseUp represents an event that the left button is raised. Unlike the press and release events of a button, the MouseDown and MouseUp events do not require the cursor to be in the range of the movie clip. Therefore, if you want to determine which movie clip the mouse clicks specifically, you also need to detect the mouse position. For example, the following code causes a movie clip to respond to the left button press event and display the cursor position in the Output window:
Onclipevent (MouseDown) {
Trace ("x coordinates:" +_root._xmouse);
Trace ("Y-coordinate:" +_root._ymouse);
}
Here, _root._xmouse and _root._ymouse represent the x-coordinate and y-coordinate of the cursor relative to the main scene, and if _root is omitted, the coordinates of the cursor relative to the movie clip itself are obtained.
2. Right button
The right and middle keys of the mouse are the new open features of Flash MX 2004. The response to the right mouse button is mainly reflected in the shortcut menu that allows the user to customize the right key.
The ContextMenu class represents a shortcut menu, and the Contextmenuitem class represents a menu item in a shortcut menu. The code shown below creates an object of the ContextMenu class my_cm:
var my_cm = new ContextMenu ();
The Customitems property of the ContextMenu class is an array that contains all the menu items from the shortcut menu. To add menu items to menus, you need to use the push method of the array, as follows:
My_cm.customItems.push (New Contextmenuitem ("Rotation", func_rotate));
In this way, the Rotate menu item is added to the shortcut menu, and Func_rotate is a function name that determines the command to be executed when the Rotate menu is selected. This function is defined below:
function Func_rotate (Obj:object, Menu:contextmenu) {
Obj.onenterframe = function () {
This._rotation + 15;
};
}
The parameter obj here is automatically captured and passed by the system, which is the object that responds to the right mouse button and displays the shortcut menu. The above function makes the object rotate at the speed of the 15°/frame when you select the Rotate shortcut menu.
3. Middle Key
In a Windows environment, the middle mouse button is often used to roll the screen--when you are using Word, browsing the web, even making a choice in a Drop-down list box--and now it's time to watch Flash. Of course, this is also due to Flash MX 2004.
Indicates that the middle key scrolling event is not defined in the mouse object of the mouse, and Flash MX 2004 provides a OnMouseWheel listener to detect the middle key scrolling. Therefore, to make it possible to respond to the scrolling of the middle mouse button, you must register the OnMouseWheel listener with the mouse object. The code is as follows:
MouseListener = new Object ();
Mouselistener.onmousewheel = function (Delta) {
Clip_mc._x + = n * Delta;
}
Mouse.addlistener (MouseListener);
Where Delta represents the number of rows that the screen scrolls with each scrolling tick of the middle mouse button, and its value is determined by the system, often between 1~3. The above code causes the instance CLIP_MC to move N*delta pixels to the left or right once when the middle mouse button is scrolled, and the direction of movement is determined by the direction in which the middle key scrolls.
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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service