当 wmode=opaque 或 wmode=transparent 时如何检测 Event.MOUSE_LEAVE
我有一个自定义的拖动事件,适用于大多数情况:
stage.addEventListener( MouseEvent.MOUSE_DOWN, beginDrag );
function beginDrag( e:MouseEvent )
{
stage.addEventListener( MouseEvent.MOUSE_MOVE, drag );
stage.addEventListener( MouseEvent.MOUSE_UP, endDrag );
stage.addEventListener( MouseEvent.DEACTIVATE, endDrag );
stage.addEventListener( Event.MOUSE_LEAVE, endDrag );
stage.addEventListener( Event.REMOVED_FROM_STAGE, stageEndDrag );
//trigger beginDrag event
}
function drag( e:MouseEvent )
{
//trigger drag event
}
function endDrag( e:Event )
{
stage.removeEventListener( MouseEvent.MOUSE_MOVE, drag );
stage.removeEventListener( MouseEvent.MOUSE_UP, endDrag );
stage.removeEventListener( MouseEvent.DEACTIVATE, endDrag );
stage.removeEventListener( Event.MOUSE_LEAVE, endDrag );
stage.removeEventListener( Event.REMOVED_FROM_STAGE, stageEndDrag );
//trigger endDrag event
}
问题是,当我将此代码与 wmode=transparent
或 wmode=opaque
一起使用时,MOUSE_LEAVE<当
MOUSE_UP
事件发生在舞台外时,未检测到 /code> 事件。
当wmode
为透明
或不透明
时,有没有办法检测MOUSE_LEAVE
事件?
或
有没有办法检测wmode
设置为透明
或不透明
以便解决方法可以实施吗?
I have a customized drag event that works great for most things:
stage.addEventListener( MouseEvent.MOUSE_DOWN, beginDrag );
function beginDrag( e:MouseEvent )
{
stage.addEventListener( MouseEvent.MOUSE_MOVE, drag );
stage.addEventListener( MouseEvent.MOUSE_UP, endDrag );
stage.addEventListener( MouseEvent.DEACTIVATE, endDrag );
stage.addEventListener( Event.MOUSE_LEAVE, endDrag );
stage.addEventListener( Event.REMOVED_FROM_STAGE, stageEndDrag );
//trigger beginDrag event
}
function drag( e:MouseEvent )
{
//trigger drag event
}
function endDrag( e:Event )
{
stage.removeEventListener( MouseEvent.MOUSE_MOVE, drag );
stage.removeEventListener( MouseEvent.MOUSE_UP, endDrag );
stage.removeEventListener( MouseEvent.DEACTIVATE, endDrag );
stage.removeEventListener( Event.MOUSE_LEAVE, endDrag );
stage.removeEventListener( Event.REMOVED_FROM_STAGE, stageEndDrag );
//trigger endDrag event
}
The issue is that when I use this code with wmode=transparent
or wmode=opaque
the MOUSE_LEAVE
event is not detected when the MOUSE_UP
event occurs off the stage.
Is there a way to detect the MOUSE_LEAVE
event when wmode
is transparent
or opaque
?
OR
Is there a way to detect that the wmode
is set to transparent
or opaque
so that a work-around may be implemented?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,MOUSE_LEAVE 不是一个可靠的事件。有时它会被解雇,有时则不会。您可以在网络上查找对此的投诉。
不过,您可以做一件事,那就是手动检查鼠标是否位于舞台上方:
当光标位于舞台区域之外时,这将调度 MOUSE_LEAVE 事件,而当光标位于舞台区域之外时,将调度自定义“mouseEnter”事件。重新进入。然后,您可以向舞台添加事件侦听器以可靠地对这些事件做出反应,但您必须记住,一次可能会触发多个 MOUSE_LEAVE(如果自定义事件和内置事件都执行)。您可以检查
out
变量以防止事件处理程序的双重执行。PS 我不确定这是否适用于所有 stage.align 和 stage.scaleMode 选项。它应该适用于 StageScaleMode.NO_SCALE 和 StageAlign.TOP_LEFT 的组合,对于任何其他设置,您必须检查并可能找到解决方法。
By default, MOUSE_LEAVE is not a reliable event. Sometimes it gets fired, at other times it won't. You can find complaints about this all over the web.
There is one thing you can do, though, and that is to manually check if the mouse is over the stage:
This will dispatch the MOUSE_LEAVE event when the cursor is outside of the stage area, and the custom "mouseEnter" event, when it reenters. You can then add event listeners to the stage to reliably react to these events, but you have to keep in mind that more than one MOUSE_LEAVE might be fired at a time (if both the custom one and the built-in one are executed). You can check the
out
variable to prevent double execution of the event handlers.P.S. I am not sure this works for all stage.align and stage.scaleMode options. It should work for the combination of StageScaleMode.NO_SCALE and StageAlign.TOP_LEFT, for any other settings you will have to check and possibly find a workaround.