AS3 可在 y 轴上拖动 layer/mask
AS3 Draggable layer/mask on y axis
我想创建这个确切的例子:http://www.nytimes.com/2008/12/28/nyregion/18thennow.html?_r=2&
但是,拖动发生在 y 轴而不是 x 轴上。我正在使用一些基本代码,但想知道如何将其锁定到位?
myImage.mask = myMask;
stage.addEventListener(MouseEvent.MOUSE_DOWN, fMouseDown);
stage.addEventListener(MouseEvent.CLICK, fMouseUp);
function fMouseDown(e:MouseEvent):void {
myMask.startDrag();
}
function fMouseUp(e:MouseEvent):void {
myMask.stopDrag();
}
虽然这不是我需要的,有什么帮助吗?提前致谢!
The documentation of startDrag() 告诉你第二个可选参数 bounds
:
bounds:Rectangle (default = null) — Value relative to the coordinates of the Sprite's parent that specify a constraint rectangle for the Sprite.
y 轴是一个零宽度的矩形。
为了同时拖动手柄和蒙版,请将两者放入容器 Sprite
对象中。这应该是您调用 startDrag
和 stopDrag
的对象。
但是由于您只想在按下手柄(而不是整个掩码)时启动拖动,因此请在处理程序上注册鼠标事件的侦听器。
我想创建这个确切的例子:http://www.nytimes.com/2008/12/28/nyregion/18thennow.html?_r=2& 但是,拖动发生在 y 轴而不是 x 轴上。我正在使用一些基本代码,但想知道如何将其锁定到位?
myImage.mask = myMask;
stage.addEventListener(MouseEvent.MOUSE_DOWN, fMouseDown);
stage.addEventListener(MouseEvent.CLICK, fMouseUp);
function fMouseDown(e:MouseEvent):void {
myMask.startDrag();
}
function fMouseUp(e:MouseEvent):void {
myMask.stopDrag();
}
虽然这不是我需要的,有什么帮助吗?提前致谢!
The documentation of startDrag() 告诉你第二个可选参数 bounds
:
bounds:Rectangle (default = null) — Value relative to the coordinates of the Sprite's parent that specify a constraint rectangle for the Sprite.
y 轴是一个零宽度的矩形。
为了同时拖动手柄和蒙版,请将两者放入容器 Sprite
对象中。这应该是您调用 startDrag
和 stopDrag
的对象。
但是由于您只想在按下手柄(而不是整个掩码)时启动拖动,因此请在处理程序上注册鼠标事件的侦听器。