Flash-Rotation

Posted by druva | Flash, as3, utils | Wednesday 15 October 2008 1:35 am

This shows how you can rotation a button around itself on clicking and moving the mouse.


rotator.addEventListener(MouseEvent.MOUSE_DOWN, initialize);
rotator.addEventListener(MouseEvent.MOUSE_MOVE, mouseMover);
rotator.addEventListener(MouseEvent.MOUSE_UP, deinitialize);

var dragging;
var actual_mouse_angle;
var actual_rotation;
var actual_x;

function initialize(evt:Event){
 dragging = true;
 actual_mouse_angle = Math.atan2(mouseY-rotator.y, mouseX-rotator.x) * 180/Math.PI;
 actual_rotation = rotator.rotation;
 actual_x = mouseX;
}

function mouseMover(evt:Event){
 if(dragging){
 curr_mouse_angle = Math.atan2(mouseY-rotator.y, mouseX-rotator.x) * 180/Math.PI;
 rotator.rotation = actual_rotation + curr_mouse_angle - actual_mouse_angle;
 }
}

function deinitialize(evt:Event){
 dragging = false;
}

download source code

This movie requires Flash Player 9