
Код AS3:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Matrix;
public class Main extends Sprite
{
static public const STAGE_WIDTH:int = 800;
static public const STAGE_HEIGHT:int = 600;
private var $mover:Sprite;
private var prevPhi:Number;
private var $rotation:Number;
public function Main()
{
$mover = new Sprite();
var mx:Matrix = new Matrix();
mx.createGradientBox(STAGE_HEIGHT / 2, STAGE_HEIGHT / 2, Math.PI / 2);
$mover.graphics.beginGradientFill('linear', [0xFF0000, 0x0000FF], [1, 1], [0, 255], mx);
$mover.graphics.drawCircle(0, 0, STAGE_HEIGHT / 2);
$mover.graphics.endFill();
$mover.x = STAGE_WIDTH / 2;
$mover.y = STAGE_HEIGHT / 2;
this.addChild($mover);
this.addEventListener(Event.ADDED_TO_STAGE, thisAddedToStageHandler);
}
private function thisAddedToStageHandler(e:Event):void
{
this.removeEventListener(Event.ADDED_TO_STAGE, thisAddedToStageHandler);
stage.addEventListener(MouseEvent.MOUSE_DOWN, moverMouseDownHandler);
stage.addEventListener(MouseEvent.MOUSE_UP, moverMouseUpHandler);
}
private function moverMouseDownHandler(e:MouseEvent):void
{
prevPhi = Math.atan2(stage.mouseY - $mover.y, stage.mouseX - $mover.x);
$rotation = $mover.rotation;
$mover.addEventListener(MouseEvent.MOUSE_MOVE, moverMouseMoveHandler);
}
private function moverMouseUpHandler(e:MouseEvent):void
{
$mover.removeEventListener(MouseEvent.MOUSE_MOVE, moverMouseMoveHandler);
}
private function moverMouseMoveHandler(e:MouseEvent):void
{
const speed:Number = 0.3;
var phi:Number = Math.atan2(stage.mouseY - $mover.y, stage.mouseX - $mover.x);
var step:Number = phi - prevPhi;
if (step > Math.PI)
step -= 2 * Math.PI;
else if (step < -Math.PI)
step += 2 * Math.PI;
//тут можно делать с шагом что угодно
step *= speed;
$rotation += step * 180 / Math.PI;
prevPhi = phi;
$mover.rotation = $rotation;
}
}
}