Tutorial details:
Written by: Kyle McDonald
Website: www.kylemcdonald.com

INTRODUCTION

I am writing this tutorial because I feel that the current tutorial on actionscript.org which defines how to detect the angle of a mouse relative to an object on the screen is unnecesarily complex. Instead of going through sine tables, I think that it would be much better if you understand how to do two things in a simpler way:

1.) Detect the angle created by the mouse and a movie clip symbol.
2.) Rotate a movie clip symbol about its vertex based on the position of the mouse.

PART 1: Back to the basics: Trigenometry and Algebra

When you are detecting the angle of the mouse relative to an object, what you are really doing is finding the angle (aka "theta") in the triangle created by the x,y position of the mouse, the 0,0 position of the vertex of the movie clip symbol, and the horizontal line that passes through the vertex of the movie clip symbol.

If anybody remembers the pnumatic device "sohcahtoa", then you might remember it means:

sin()=(opposite/hypotenuse)

You can see where "opposite", "adjacent", and "hypostenuse" are by looking at the next picture.

Also, just incase you are wondering, "opposite", "adjacent", and "hypostenuse" are lengths of the sides of the triangle. So, since everyone past about 8th grade knows, it takes a little bit more math to find the hypotenuse, and since we already have the length of the adjacent and opposite sides (the x and y of the mouse relative to the movie clip symbol, in this case the mouse) we can just go ahead and use algebra to manipulate this equation to solve for :

`_root.text=Math.atan(1);stop();`
`_root.text=Math.atan(1)/(Math.PI/180);stop();`