I l @ ve RuBoard |
Not only can you get the location of a movie clip on the screen, you can even get the location of the mouse, also known as the cursor.
Two special properties of the Flash player tell you the horizontal and vertical positions of the cursor on the screen. These are the _xmouse and _ymouse properties. But what are they properties of? If used by themselves , _xmouse and _ymouse are properties of the object they are contained in. So if you use them in the main timeline, they are root properties. If you use them in a movie clip, they are movie clip properties. What's the difference? Well, _xmouse and _ymouse measure the mouse location from registration point of the object. So if you are using the root properties, you get the location of the mouse from the upper-left corner of the movie. If you use them inside a movie clip, you get the mouse location from the center of the movie clip. In most cases, you will want these properties as they relate to the main movie. To ensure this, you can use _root._xmouse and _root._ymouse . Here is the code inside the example movie 07mouse.fla. It contains a movie clip with this script on it. In every frame that passes , the script will write the x and y location of the mouse to the Output window, followed by a blank line to separate the pairs of numbers . onClipEvent (enterFrame) { trace(_root._xmouse); trace(_root._ymouse); trace(""); } When you run this movie, you will see the pairs of numbers stream through the Output window. Move the mouse around and watch the numbers change. Bring the cursor up near the upper-left corner of the screen to see them get close to 0, 0 and then to the lower-right to see them get close to 550, 400.
|
I l @ ve RuBoard |