Fly move according to the mouse movement
This code shows the movement of the object fly according to the mouse movement
var flySpeed:Number = 0.1;
fly.addEventListener(Event.ENTER_FRAME,flyMove);
function flyMove(event:Event):void {
var fly_x:Number = (mouseX - fly.x) * flySpeed;
var fly_y:Number = (mouseY - fly.y) * flySpeed;
var angle = Math.atan2(fly_y, fly_x);
fly.x += fly_x;
fly.y += fly_y;
fly.rotation = 90 +(angle * 180 / 3.141593E+000);
}
This movie requires Flash Player 9
Flash Rotation2
This is another way of rotation related to my previous post
Rotation changes depending on the mousex position
rotator.addEventListener(MouseEvent.MOUSE_DOWN, initialize);
rotator.addEventListener(MouseEvent.MOUSE_MOVE, mouseMover);
rotator.addEventListener(MouseEvent.MOUSE_UP, deinitialize);
var dragging;
var actual_rotation;
var mouse_pos;
function initialize(evt:Event){
mouse_ref = mouseX;
dragging = true;
actual_rotation = rotator.rotation;
}
function mouseMover(evt:Event){
if(dragging){
rotator.rotation = actual_rotation + (mouseX - mouse_pos)* 3;
}
}
function deinitialize(evt:Event){
dragging = false;
}
This movie requires Flash Player 9
Flash-Rotation
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;
}
This movie requires Flash Player 9