Rotating and moving the image using action script

Posted by druva | Flash, as3, utils | Tuesday 9 February 2010 5:14 am

druva.addEventListener(Event.ENTER_FRAME, rightAnimation);

function rightAnimation (e:Event):void {
  if (druva.x <= 300) {
	druva.x += 1;
	if (druva.x > 300) {
	  druva.x -= 300;
	}
	druva.rotation += 10;
  }
}

This movie requires Flash Player 9

 

Fly move according to the mouse movement

Posted by druva | CSS, Flash, as3, utils | Sunday 21 December 2008 2:45 am

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

Posted by druva | Flash, as3 | Friday 17 October 2008 8:00 am

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

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