Actionscript 3 - 检测单击以缩放或拖动

发布于 08-11 09:42 字数 595 浏览 8 评论 0原文

我正在使用 Actionscript 3,并且正在构建一个图像查看器。到目前为止,我有以下功能,基于“onClick”鼠标事件:

1)当查看正常大小的图像时,单击将显示“缩放”图像。
2) 查看缩放图像时,单击将显示“正常”图像。

很棒的东西。

现在我想应用以下行为,以便用户可以放大并拖动缩放的图像 - 并勾勒出以下内容:

1)删除了 onClick 事件
2) 添加一个“onMouseDown”事件,记录鼠标按下时的鼠标XY
3) 添加一个“onMouseUp”事件,并在鼠标抬起时记录鼠标XY
4) 如果 XY onMouseDown = XY onMouseUp 则假设发生 Click 事件 - 所以 Zoom
5) 如果 XY onMouseDown != XY onMouseUp 则假设发生一个 Drag 事件 - 因此拖动图像

现在这仅在用户单击时手稳的情况下才有效 - 并且感觉不是一个很好的解决方案。如果用户的手不稳定,则当他们真正想要缩小时,会假设发生拖动事件...

任何人都可以建议一种比我上面概述的更好的方法来检测是拖动图像还是缩放图像吗?

感谢您的想法/帮助,

高级椰子。

I'm using Actionscript 3, and am building an image viewer. So far, I have the following functionality, based around the "onClick" mouse event:

1) When viewing the normal sized image, clicking will display a "zoomed" image.
2) When viewing the zoomed image, clicking will display the "normal" image.

Great stuff.

Now I want to apply the following behaviour, so the user can zoom in, and drag the zoomed image around - and have sketched out the following:

1) Removed the onClick event
2) Add an "onMouseDown" event, to record the mouse XY on mouse down
3) Add a "onMouseUp" event, and record the mouse XY on mouse up
4) If the XY onMouseDown = XY onMouseUp then assume a Click event - so Zoom
5) If the XY onMouseDown != XY onMouseUp then assume a Drag event - so drag the image

Now this only works if the user has a steady hand while clicking - and doesn't feel like a great solution. If the user has an unsteady hand, a drag event is assumed when they really wanted to de-zoom...

Can anyone suggest a better way of detecting whether to Drag the image or to Zoom the image than I have sketched out above?

Thank you for your thoughts / help,

Senior coconut.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

源来凯始玺欢你2024-08-18 09:42:24

基本伪代码如下:

import flash.utils.getTimer;

private var clickTime:uint;

function onMouseDown(event:Event):void {
    this.clickTime = getTimer();

    // Start drag even if they intend to zoom -- it won't hurt if it shifts a
    // couple pixels before zooming out
    startDrag();
}

function onMouseUp(event:Event):void {
    var delta = getTimer() - this.clickTime;

    // It's been less than a quarter second, so user probably meant to zoom
    // in/out.  Adjust this number to taste if it seems too low or high.
    if (delta < 250)
        toggleZoom();

    stopDrag();
}

Basic pseudocode follows:

import flash.utils.getTimer;

private var clickTime:uint;

function onMouseDown(event:Event):void {
    this.clickTime = getTimer();

    // Start drag even if they intend to zoom -- it won't hurt if it shifts a
    // couple pixels before zooming out
    startDrag();
}

function onMouseUp(event:Event):void {
    var delta = getTimer() - this.clickTime;

    // It's been less than a quarter second, so user probably meant to zoom
    // in/out.  Adjust this number to taste if it seems too low or high.
    if (delta < 250)
        toggleZoom();

    stopDrag();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文