Toxiclab.org

Mouse X, Y position

11.6.2008, 14:49
Submited in: Flash | Total Views: 77935

In this easy, detailed Flash lesson, I will show you how to create X and Y mouse position using the action script code.



Step 1

Create a new flash document. Press Ctrl+J key on the keyboard (Document Properties) and set the width and the height of your document as whaterver you like. Select any color as background color. Set your Flash movie's frame rate to 24 and click ok.



Step 2


Take now the Text Tool (A) and type somewhere on the stage X and Y. See the picture below.



Step 3

Takle the Text Tool (A) and go to the Properties Panel again (Ctrl+F3) and select the following options:

a) Select a Dynamic Text field.
b) Select any font.
c) Choose any size for font.
d) Select any color for font.
e) As the rendering option, select Anti - alias for readability.
f) for Var type: xvalue



Step 4

Then, draw a rectangle on the right side of X letter. See the picture below.



Do this also for letter Y, but for Var type: yvalue



Step 5

Create a new layer above the layer 1 (layer 2).

Step 6

Select layer 2, take the Rectangle Tool (R) and draw a vertical rectangle line like it is shown on the picture below.



Step 7

While the vertical line is still selected, press F8 key (Convert to Symbol) to convert this vertical line into a Movie Clip Symbol. See the picture below.



Step 8

Take now the Selection Tool (V), click once on the vertical line and go to the Action Script Panel (F9). Then, enter this code inside the actions panel:

onClipEvent(enterFrame) {
this._x = _root.xvalue = _root._xmouse;
}

Step 9

Take now again the Rectangle Tool (R) and draw a horizontal line.



Step 10

While the horizontal line is still selected, press again F8 key (Convert to Symbol) to convert this horizontal line into a Movie Clip Symbol.

Step 11

Select that horizontal line using the Selection Tool (V) and go again to the A.S. panel and enter this code inside the actions panel:

onClipEvent(enterFrame) {
this._y = _root.yvalue = _root._ymouse;
}

We're done!

Test your movie and enjoy!

Download example

Are you a website owner?
Click here to register and submit your tutorials!

Browse by category


Most popular tutorials


Resources Worth visiting


Friends