flash on 2011-5-18
/**
* Copyright PrettyMuchBryce ( http://wonderfl.net/user/PrettyMuchBryce )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/mxIP
*/
package {
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.Sprite;
public class RotationTest extends Sprite {
private var rect:Sprite;
private var ui:Sprite;
private var rotateBox:Boolean;
public function RotationTest():void {
buildStuff();
ui.addEventListener(MouseEvent.MOUSE_DOWN,downRotate);
stage.addEventListener(MouseEvent.MOUSE_UP,upRotate);
stage.addEventListener(Event.ENTER_FRAME,update);
}
private function buildStuff():void {
rect = new Sprite();
rect.graphics.beginFill(0xFF0000,1);
rect.graphics.drawRect(-20,-20,40,40);
rect.graphics.endFill();
ui = new Sprite();
ui.graphics.beginFill(0x000000);
ui.graphics.drawCircle(20,-20,5);
ui.graphics.drawCircle(20,20,5);
ui.graphics.drawCircle(-20,20,5);
ui.graphics.drawCircle(-20,-20,5);
rect.x = 250;
rect.y = 250;
rect.addChild(ui);
addChild(rect);
}
private function downRotate(e:MouseEvent):void {
rotateBox=true;
}
private function upRotate(e:MouseEvent):void {
rotateBox=false;
}
private function update(e:Event):void{
if (rotateBox) {
var xdiff:Number = mouseX-rect.x;
var ydiff:Number = mouseY-rect.y;
rect.rotation = Math.atan2(ydiff, xdiff)/(Math.PI/180) + 45;
//textbox.text = "ROTATION: " + Math.round(rect.rotation).toString();
}
}
}
}