【发布时间】:2011-09-12 20:50:01
【问题描述】:
我有一个应用程序,用户在其中上传图像,然后通过单击、拖动和使用调整大小栏对其进行转换。但是我的客户要求我限制用户可以拖动到的位置,这不是问题,除非我需要与正常情况相反的限制。
所以我有 startDrag(false, new Rectangle...) 工作得很好,但我需要的是让用户能够拖动边界之外并且在闪光灯内部没有空白文件。
我的意思是说我有一个 500 像素宽的 flash 文件和其中的一个图像,我不小心在其中拖动。如果图像的右侧边缘(如果我向左拖动)达到 500 像素,它将停止拖动并且不允许它们向左再拉。
我真的希望我已经很好地解释了这一点,任何指导都会很棒!
以下是我目前用于拖动事件的代码。
任何帮助将不胜感激。
public function startImageDrag (e:MouseEvent):void {
mousePos['x'] = e.target.mouseX;
mousePos['y'] = e.target.mouseY;
imageDraggable.removeEventListener(MouseEvent.MOUSE_DOWN, function ():void {});
photoapp.cStage.addEventListener(MouseEvent.MOUSE_MOVE, moveImage);
photoapp.cStage.addEventListener(MouseEvent.MOUSE_UP, endImageDrag);
}
//The type is wildcarded because I have this hooked to MOUSE_LEAVE too
public function endImageDrag (e:*):void {
photoapp.cStage.removeEventListener(MouseEvent.MOUSE_MOVE, moveImage);
photoapp.cStage.addEventListener(MouseEvent.MOUSE_DOWN, startImageDrag);
}
public function moveImage(event:MouseEvent):void {
//Get the offset of the current mouse position over the image
var
//The mouse position on the stage
sxOff:Number = photoapp.cStage.mouseX,
syOff:Number = photoapp.cStage.mouseY,
//The position on which the mouse down event was on the image
reX:Number = sxOff - mousePos['x'],
reY:Number = syOff - mousePos['y'],
//The iamge object
i:DisplayObject = imageDraggable;
//Move the image
if (/*I have no idea now...*/) {
imageDraggable.x = reX;
}
if (iY) {
imageDraggable.y = reY;
}
event.updateAfterEvent();
}
【问题讨论】:
标签: flash actionscript-3 actionscript