假设您正在使用MOUSE_DOWN - > MOUSE_MOVE - > MOUSE_UP过程,您可以使用它。它最初被用作需要平滑拖放的人的答案。你可以看到答案here。
import flash.display.*;
import flash.events.*;
var startX:Number;
var startY:Number;
var shape:Sprite = new Sprite();
shape.graphics.beginFill(0x000000);
shape.graphics.drawRect(0,0,50,50);
shape.graphics.endFill();
this.addChild(shape);
shape.addEventListener(MouseEvent.MOUSE_DOWN,this.mouseDown);
function mouseDown(e:MouseEvent = null):void{
stage.frameRate = 60;
startX = stage.mouseX - shape.x;
startY = stage.mouseY - shape.y;
stage.addEventListener(MouseEvent.MOUSE_MOVE,this.mouseMove);
shape.addEventListener(MouseEvent.MOUSE_UP,this.mouseUp);
}
function mouseMove(e:MouseEvent = null):void{
shape.x = stage.mouseX - startX;
shape.y = stage.mouseY - startY;
}
function mouseUp(e:MouseEvent = null):void{
shape.removeEventListener(MouseEvent.MOUSE_UP,this.mouseUp);
stage.removeEventListener(MouseEvent.MOUSE_MOVE,this.mouseMove);
stage.frameRate = 24;
}
基本上,来完成你想要什么,该MOUSE_MOVE事件侦听器必须连接到舞台上,而不是在面板或图像。您在图像上侦听MOUSE_DOWN(或右键单击),然后添加MOUSE_MOVE和MOUSE_UP事件。我的帧率变化是不必要的,但是为了获得原始提问者想要的平滑拖动,需要进行更改。我还补偿了该代码中对象内的鼠标位置。关键是肯定要将MOUSE_MOVE事件添加到舞台上,并监听stage.mouseX和stage.mouseY,而不是将其添加到面板或图像并侦听target.mouseX/mouseY或event.localX/localY。
我不认为这是用于移动,但如果是,并且您正在使用强制DPI,请确保您使用FlexGlobals.topApplication.systemManager.mouseX/mouseY而不是stage.mouseX和stage.mouseY 。 SystemManager类占DPI变化,Stage类不占用。
请张贴您的代码。没有看到代码,很难提供任何解决方案。 –