Math Functions

Move the mouse and see the arrow turn.

Get Adobe Flash player
stage.addEventListener(MouseEvent.MOUSE_MOVE,turnArrow);
function turnArrow(e:MouseEvent): void {
	var dx:int=e.stageX - arrow.x;  // x distance of arrow  from cursor
	var dy:int=e.stageY - arrow.y;  // y distance of arrow  from cursor
  	var radians:Number=Math.atan2(dy,dx);  //get angle in radians 
  	arrow.rotation=radians*180/Math.PI; //convert  radians to degrees
	txtRotation.text=""+Math.round(arrow.rotation); //show the rotation
} //turn arrow
Save the fla file to your computer to experiment.
Experiment: Make a dial using mouse down on the dial instead of the stage.
Experiment: Create a Dial class with public variables for max and min.

NEXT: A Yo-yo with sin function