Flash actionscript 3鼠标退出



我使用下面的代码在舞台上拖动一个对象。我使用一个矩形来限制对象的移动到x轴。我需要鼠标停止拖动时,它是外部的对象。按钮模式关闭,但当鼠标移动并按下鼠标按钮时,鼠标仍然拖动对象。下面是我使用的代码:

var rectangle:Rectangle = new Rectangle(-1400, 600, 4500, 0);
stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseStartDrag);
function mouseStartDrag(motion:MouseEvent):void
{
    strip_mc.startDrag(false, rectangle);
}
stage.addEventListener(MouseEvent.MOUSE_UP, mouseStopDrag);
function mouseStopDrag(motion:MouseEvent):void 
{
    strip_mc.stopDrag();
}
strip_mc.buttonMode = true; 
Thanks for any help 

可以检测鼠标是否在矩形内如果不在则可以调用strip_mc.stopDrag();

首先创建一个空的影片剪辑,并添加矩形。

var m:MovieClip = new MovieClip(); 
m.addChild(rectangle);
stage.addChild(m);

然后像这样做:

m.addEventListener(MouseEvent.MOUSE_OUT, mouseStopDrag);

m.addEventListener(MouseEvent.ROLL_OUT, mouseStopDrag);

事件侦听器将调用已经创建的mouseStopDrag,从而停止拖动。

最新更新