Actionscript 3 - 检测单击以缩放或拖动
我正在使用 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.
基本伪代码如下:
Basic pseudocode follows: