Actionscript 3 Flash actionscript 3鼠标退出
我使用下面的代码在舞台上拖动一个对象。我使用一个矩形来限制对象只在x轴上移动。我需要鼠标在对象之外时停止拖动。buttonmode关闭,但当鼠标向下移动时,鼠标仍会拖动对象。以下是我正在使用的代码:Actionscript 3 Flash actionscript 3鼠标退出,actionscript-3,Actionscript 3,我使用下面的代码在舞台上拖动一个对象。我使用一个矩形来限制对象只在x轴上移动。我需要鼠标在对象之外时停止拖动。buttonmode关闭,但当鼠标向下移动时,鼠标仍会拖动对象。以下是我正在使用的代码: var rectangle:Rectangle = new Rectangle(-1400, 600, 4500, 0); stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseStartDrag); function mouseStartDrag(m
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()代码>
首先创建一个空movieclip并将矩形添加到其中
var m:MovieClip = new MovieClip();
m.addChild(rectangle);
stage.addChild(m);
然后做一些类似的事情:
m.addEventListener(MouseEvent.MOUSE_OUT, mouseStopDrag);
或
然后,事件侦听器将调用已经创建的mouseStopDrag
,从而停止拖动“1061:通过静态类型flash.geom:Rectangle的引用调用可能未定义的addEventListener方法。@Brian Berry您可以将矩形添加到空movieclip中,然后引用它。-我更新了我的答案。
m.addEventListener(MouseEvent.ROLL_OUT, mouseStopDrag);