website promotion banner
eturnkeys
Your Ad Here
Flash & Swish  Home Flash & Swish Flash Tutorials Detecting Direction of Cursor
rss

Detecting Direction of Cursor

Author: 10Steps.SG More by this author


Preparations:

Create a new flash file (ActionScript 2.0) and save it as test.fla in this case.

Detecting Direction of Cursor image 1

Step 1:

Draw an arrow on the Stage.

Detecting Direction of Cursor image 2

Step 2:

Convert the arrow into a movieclip Symbol with instance name my_mc. Double-click on my_mc and centralize the arrow to the Stage.

Detecting Direction of Cursor image 3

Step 3:

Create a layer on top of the object layer and name it as actions.

Detecting Direction of Cursor image 4

Step 4:

Right-click on the frame and select Actions to open up the Actions panel.

Detecting Direction of Cursor image 5

Step 5:

Insert these codes inside the Actions panel.

That's all!

function detectDirection(item) {
var dx = item._x-_xmouse;
var dy = item._y-_ymouse;
var angle = Math.atan2(dy, dx);
item._rotation = angle/Math.PI*180-90;
}
_root.onEnterFrame=function(){
detectDirection(my_mc);
}


Author's URL: 10steps.sg

Rate this Material: Bad 1 2 3 4 5 Excellent
print this page tell a friend subscribe to newsletter subscribe to rss

Add comments to "Detecting Direction of Cursor"