AS3 项目 - 鼠标移动侦听器在应用程序外部做出反应

发布于 2024-07-22 20:27:07 字数 825 浏览 5 评论 0原文

我有一种不寻常的行为,我似乎无法弄清真相。 当我运行它时,如果我在 swf 区域中移动,它会在鼠标移动时正常跟踪。 值得期待的。

但当我点击屏幕上的任何地方时,它会跟踪移动事件。 如果我单击并拖动,它会跟踪,就像我在浏览器的 swf 区域中移动一样。

这是代码。 我已经简化为准系统。 只需将其放入 Flex 中名为“Engine”的空 AS3 项目中即可 - 显然没有引号。

package {
import flash.display.Sprite;
import flash.events.MouseEvent;

[SWF(width='640', height='360', backgroundColor='#888888', frameRate='31')]
public class Engine extends Sprite
{       
    public function Engine()
    {
        // Add the mouse handlers
        stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
    }

    public function mouseMoveHandler(evt:MouseEvent):void
    {
        trace("move");
    }
}
}

作为一种解决方法,我添加了 MOUSE_MOVE 和 MOUSE_OVER 并在 MOUSE_OUT 上将其删除。 但这种行为似乎仍然很不寻常,我有兴趣了解为什么会发生这种情况。

谁能告诉我如何将事件限制在应用程序的实际阶段?

I'm getting an unusual behavior that I can't seem to get to the bottom of. When I run this, if I move in the swf area it traces normally on mouse move. To be expected.

But it's tracing for the move event when I click anywhere on screen. If I click and drag, it traces as if I were moving in the swf area of the browser.

Here's the code. I've simplified to it's barebones. Just put this in in an empty AS3 project in Flex called "Engine" - sans quotes obviously.

package {
import flash.display.Sprite;
import flash.events.MouseEvent;

[SWF(width='640', height='360', backgroundColor='#888888', frameRate='31')]
public class Engine extends Sprite
{       
    public function Engine()
    {
        // Add the mouse handlers
        stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
    }

    public function mouseMoveHandler(evt:MouseEvent):void
    {
        trace("move");
    }
}
}

As a workaround I've add the MOUSE_MOVE one MOUSE_OVER and remove it on MOUSE_OUT. But the behavior still seems quite unusual and I'd be interest in understanding why it's happening.

Can anyone tell me how I can keep the events constrained to the actual stage of the application?

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

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

发布评论

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

评论(3

雨的味道风的声音 2024-07-29 20:27:08

如果您在 Flash 影片内部单击并将鼠标拖动到其外部,MOUSE_MOVE 事件将继续触发,直到您释放鼠标。 MOUSE_LEAVE 仅当您在播放器外部释放鼠标时才会触发。 这就是 Flash Player 的工作原理。

也许我错了,但我认为你无法改变这种行为。

If you click inside your flash movie and drag the mouse outside of it, MOUSE_MOVE event will continue to trigger until you release your mouse. MOUSE_LEAVE will trigger only when you release the mouse outside the player. This is how Flash Player works.

Maybe I'm wrong but I don't think you can change this behaviour.

倾`听者〃 2024-07-29 20:27:08

好的,这是一个已知错误,仅发生在 Mac 上。

这里有一个修复:

http://www.visible -form.com/blog/transformmanager-fix-for-mac-firefox/

Ok, This is a known bug that only happens with Mac.

There is a fix here :

http://www.visible-form.com/blog/transformmanager-fix-for-mac-firefox/

树深时见影 2024-07-29 20:27:07

正如已经提到的,您无法阻止这些事件的触发。 它们会被触发,直到您释放鼠标为止。

您可以做的是将 MouseEvent 的坐标与舞台边界进行比较,并忽略外部的坐标。

public function mouseMoveHandler(evt:MouseEvent):void
{
    if (evt.stageX >= 0 && evt.stageX <= stage.stageWidth &&
        evt.stageY >= 0 && evt.stageY <= stage.stageHeight)
    {
        trace("move");
    }
}

As already mentioned, you can't stop these events from firing. They are triggered until you release the mouse.

What you can do is compare the coordinates of the MouseEvent with the bounds of the stage and ignore those outside.

public function mouseMoveHandler(evt:MouseEvent):void
{
    if (evt.stageX >= 0 && evt.stageX <= stage.stageWidth &&
        evt.stageY >= 0 && evt.stageY <= stage.stageHeight)
    {
        trace("move");
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文