Forked from: keno42's マウスの回転を検出 diff:31 forked from: マウスの回転を検出 nbernaz forked:0favorite:1lines:59license : MIT License modified : 2012-01-16 18:02:10 Embed Tweet // forked from keno42's マウスの回転を検出 package { import flash.display.Sprite; import flash.events.*; import flash.display.*; public class FlashTest extends Sprite { private var index:int = 0; private var stageXs:Array = []; private var stageYs:Array = []; private var wheel:Wheel = new Wheel(); // マウスを右方向に回すとホイールが右回転、逆は左回転します。 public function FlashTest() { // write as3 code here.. init(); } private function init():void{ stageXs = [stage.mouseX, stage.mouseX]; stageYs = [stage.mouseY, stage.mouseY]; addChild(wheel); wheel.x = stage.stageWidth/2; wheel.y = stage.stageHeight/2; addEventListener(Event.ENTER_FRAME,onEnterFrame); stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove); } private function onEnterFrame(e:Event):void{ wheel.update(); } private function onMove(e:MouseEvent):void{ var lastIndex:int = index; var lastLastIndex:int = 1 - index; index = lastLastIndex; var rotZ:Number = (stageXs[lastIndex] - stageXs[lastLastIndex]) * (stage.mouseY - stageYs[lastIndex]) - (stageYs[lastIndex] - stageYs[lastLastIndex]) * (stage.mouseX - stageXs[lastIndex]); stageXs[index] = stage.mouseX; stageYs[index] = stage.mouseY; wheel.rotAccel(rotZ*1.1); } } } import flash.display.Sprite; class Wheel extends Sprite{ private var num:int = 8; private var radius:Number = 200; private var rotSpeed:Number= 0; public function Wheel(){ this.graphics.lineStyle(4); this.graphics.drawCircle(0, 0, radius); for( var i:int = 0; i < num; i++ ){ this.graphics.moveTo(0,0); this.graphics.lineTo(radius * Math.cos((2*i/num)*Math.PI), radius * Math.sin((2*i/num)*Math.PI)); } this.graphics.drawCircle(0, 0, radius); } public function rotAccel(power:Number):void{ rotSpeed += power; } public function update():void{ rotSpeed *= 0.09; this.rotation += rotSpeed; } } Code Fullscreen Preview Fullscreen novita001 lastIndex mouseY mouseX rotation MouseEvent.MOUSE_MOVE addEventListener Math.PI MouseEvent Event.ENTER_FRAME Math.cos addChild Math.sin Event Array Sprite int Number