谢谢你的回答,我还想追加提问就是能不能知道那条线旋转的角度?我想统计旋转的圈数.
网友回答
round的值就是旋转次数,顺时针转过0度角+1,逆时针转过0度角则-1
import flash.display.Sprite;
var sp:Sprite = new Sprite();
sp.graphics.lineStyle(5,0xff0000,1);
sp.graphics.moveTo(0,0);
sp.graphics.lineTo(150,0);
addChild(sp);
sp.x = stage.stageWidth / 2;
sp.y = stage.stageHeight / 2;
sp.addEventListener(MouseEvent.MOUSE_DOWN,onSelected);
var lr:Number = 0;
var cr:Number = 0;
var round:int = 0;
function onSelected(e:MouseEvent)
{onMove(null);
stage.addEventListener(MouseEvent.MOUSE_MOVE,onMove);
stage.addEventListener(MouseEvent.MOUSE_UP,onStop);
}function onMove(e:MouseEvent)
{var a:Number = mouseX - sp.x;
var b:Number = mouseY - sp.y;
if (a > 0){sp.rotation = Math.atan(b/a) * 180 / Math.PI;
}else if (a {sp.rotation = Math.atan(b/a) * 180 / Math.PI + 180;
}cr = sp.rotation;
if(cr > 0 &&cr -90)
{round+=1;
trace(round)
}elseif(cr -90 && lr > 0 && lr {round-=1;
trace(round)
}lr = sp.rotation;
if (e){e.updateAfterEvent();
}}function onStop(e:MouseEvent)
{stage.removeEventListener(MouseEvent.MOUSE_MOVE,onMove);
stage.addEventListener(MouseEvent.MOUSE_UP,onStop);
}