import flash.geom.Point;
stage.addEventListener(MouseEvent.MOUSE_DOWN,mdHandler);
stage.addEventListener(MouseEvent.MOUSE_UP,muHandler);
stage.addEventListener(MouseEvent.MOUSE_WHEEL, mouseWheelHandler);
var downPoint:Point=new Point;
function mdHandler(e:MouseEvent):void
{
stage.addEventListener(MouseEvent.MOUSE_MOVE,mmHandler);
//记录初始鼠标按下点
downPoint.x = mouseX;
downPoint.y = mouseY;
}
function mmHandler(e:MouseEvent):void
{
//计算鼠标拖动到点的坐标和鼠标按下点之间的距离
//鼠标目前所在的点减去鼠标初始点返回一个新的点
/* subtract()方法
public function subtract(v:Point):Point
从此点的坐标中减去另一个点的坐标以创建一个新点。
参数:v:Point — 要减去的点。
返回:Point — 新点。
*/
var temPoint:Point = new Point(mouseX,mouseY).subtract(downPoint);
trace(temPoint)
mc.rotationX += temPoint.y;
mc.rotationY -= temPoint.x;
//再把这个点当初始点
downPoint.x = mouseX;
downPoint.y = mouseY;
}
//滚动鼠标滑轮事件
function mouseWheelHandler(e:MouseEvent):void
{
mc.z -= e.delta * 10;
}
function muHandler(e:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE,mmHandler);
}