The realization of homemade mouse

Source: Internet
Author: User

First, we open the flash, and then go to the following interface, click the arrow point, you can open a new project



New project, of course, if you open not AS3 or open the wrong, you can change the arrow points in the diagram to the version you want, and then remember to save as a new project Oh ~ (ctrl+s)



Save File Path Customization


Next we use the Flash drawing tool to draw a mouse graph, here I do not go to demonstrate, if there is no right arrow pointing at the toolbar, you can go to the left arrow at the window-the toolbar to show him, of course, the other interface can be displayed from here




A random look of the mouse




Select all the drawing, then move the mouse over the graphic, right-click-Convert to symbol, name custom



In the point where we convert to a component, the arrow refers to the property bar (no window-properties can be recalled) in the TextBox text box of the instance name to enter MOUSE_MC (this is the name of your component, just like you have a name)





Then enter index in the text box that the arrow refers to, and then click the small pencil to the right of the text box.



will appear, and then remember Ctrl+s (Save) Oh, save the interface directly click OK. At this point, we have generated a class, which is a main class, equivalent to the main program, when we open the Flash project, the first time to execute is the program in that class.




Package
{


}
Equivalent to the meaning of the package, the equivalent of a folder, save the file, after no text equivalent to the project directory.
Of course, if it appears
Package com
{


}
Then it is equal to the specific address of this class in the COM folder of your project






Import keyword
Equivalent to the import meaning, a class can use a limited number of methods, if you do not import the package from other places, then some programs you can not use, when you want to use other programs, you have to import the class before you can use the data in this class.
Import Flash.display.MovieClip; Import MovieClip This base class, all movies (converted to symbols) must refer to the class for their own
Parent class, so the program automatically helps you import it at the beginning





public class Index extends MovieClip {
}
class, which means that this is a class, all programs of the class must be written in this, write on the outside of the error index indicates the name of this class



Public Function Index () {
}
The main program that represents this class is the program that executes once when the class is created.



You can see that each {(curly brace) has a bunch of programs before it, and then there's a way to differentiate between parentheses, the innermost front bracket and the innermost
The parentheses are a pair, then the second-to-last parenthesis and the penultimate parenthesis, and so on, and so on, are interested to learn from the distinction of the Niang program brackets.





The first thing to notice is the import of two new classes, which are clocks and clock time classes, which are the necessary classes for the Timer keyword and the timerevent keyword.
var timer:timer = new Timer (16); Create a new clock function, that is, the program that executes once every time (16 milliseconds)
Timer.addeventlistener (Timerevent.timer, My_mouse_move); Is the creation of a clock event, since the clock has been created,
Must give him a period of time to execute the program, that is, my_mouse_move, can also see
Private Function My_mouse_move (e:timerevent): void
{

}
The program written in this curly brace is the one that executes 16 milliseconds.







Write
mouse_mc.x = MouseX;
Mouse_mc.y = Mousey;
As we said earlier, the name of the original is named, then this can be understood as someone who did what,
Each component has its coordinates
So we set the coordinates, X, y
MouseX is the x-axis of your real mouse, and y is the same.
Now, we can press Ctrl+enter to try the effect.







We add the following procedure
Mouse_mc.mousechildren = false;
mouse_mc.mouseenabled = false;
These two words is to cancel this component of the click and available, if not write the words will be triggered always click on this picture error, only will he click Cancel to click the image below the picture
Mouse is need to import, Mouse.hide (), is to hide the mouse visibility, now try the effect ~





Next we copy four of the mouse we drew and name it MOUSE_MC1,MOUSE_MC2,MOUSE_MC3,MOUSE_MC4






Then select the Alpha option in the ListBox drop-down box for the style, we set MOUSE_MC1 alpha to 80,MOUSE_MC2 to 60,MOUSE_MC3 to 40,MOUSE_MC4 to 20




Then on the original basis to change as shown above, and then run the program to see its effect




Because the program is executed from the top down, so I can only move the last one, moving the first word will happen to all the errors, the specific reason can read the program to see








We create a new timer program,



Then cut all the programs written in the 21st picture into the second clock (the second clock interval is 100 milliseconds)





Final Program






, start the second method, under the As link, double-click our mouse, and then enter your name, then this is the class of your mouse.



Then right-click on the component-Edit class-ctrl+s (Save)











In this class, write the following program
This keyword, the meaning of this, in the mouse class to write this is equivalent to saying that the mouse element of the alpha-=0.01 here is 100%, then that is 1 meaning,-0.01 for the percentage is 1%, the equivalent of every 16 milliseconds color is 1% light. if () is if the alpha of the mouse is less than 0, then delete the mouse on the this.parent (This.parent is equivalent to the presence of the mouse on the stage)





Let's just remove the program here.


















The realization of homemade mouse

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.