制作蒙版下的影片剪辑可点击并响应 MouseEvents

发布于 2024-11-26 16:11:18 字数 675 浏览 0 评论 0原文

这个问题是链接上问题的后续问题: 制作已设置的影片剪辑作为可点击的掩码并响应 MouseEvents

我在舞台上的图层结构如下所示:

  • holder_mc

    • dragCanvas_mc
    • mask_mc
    • canvas_mc

DragCanvas_mc - 用于平移目的。

mask_mc - canvas_mc 的掩模

我现在面临一个问题。我无法在 canvas_mc 上注册 MouseEvents

这是必需的,因为我必须在画布上绘图,

holder_mc.canvas_mc.addEventListener(MouseEvent.MOUSE_DOWN,onStartDrawing);

function onStartDrawing(evt:MouseEvent)
{
    trace("Hello");
}

我在输出窗口中看不到 Hello。知道我哪里错了。提前致谢。

This question is a follow up to the questions on link:
Making a Movieclip which is set as mask clickable and respond to MouseEvents

The structure of your layers that I have on stage looks like this:

  • holder_mc

    • dragCanvas_mc
    • mask_mc
    • canvas_mc

dragCanvas_mc - used for panning puposes.

mask_mc - Mask for canvas_mc

I am facing a problem now. I cannot get MouseEvents to be registered on the canvas_mc

This is required because I have to make drawings to the canvas

holder_mc.canvas_mc.addEventListener(MouseEvent.MOUSE_DOWN,onStartDrawing);

function onStartDrawing(evt:MouseEvent)
{
    trace("Hello");
}

I cannot see Hello in output window. Any idea where I am wrong. Thanks in advance.

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

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

发布评论

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

评论(2

沉溺在你眼里的海 2024-12-03 16:11:18

如果“MovieClip A”在显示列表上位于“MovieClip B”之上,并且“MovieClip A”为“mouseEnabled”,则“MovieClip B”将永远不会“通过”顶部 MovieClip 接收事件。

在您的情况下,拖动画布位于上方,并且很可能附加到某些鼠标事件。如果是这种情况,您需要使用顶部剪辑(拖动画布)处理事件并将它们传递给子级或父级 Holder_mc。

holder_mc.addEventListener(MouseEvent.CLICK, onClick);

function onClick(e:MouseEvent):void {
    // do normal clicky stuff for this object
    // then..
    //

    if(canvas_mc.hitTestPoint(mouseX, mouseY, false)) {
        // do clicky stuff for canvas mc
    }    

}

有些人可能会说使用“getObjectsUnderPoint”,但它有一个已记录的错误,因此请使用 hitTestPoint() http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#hitTestPoint%28%29

If 'MovieClip A' is above 'MovieClip B' on the display list and 'MovieClip A' is 'mouseEnabled' then 'MovieClip B' will never receive the events "through" the top MovieClip.

In your case, the drag canvas is above, and is most likely attached to some mouse events. If this is the case, you need to handle the events with the top clip (drag canvas) and pass them through to the children, or the parent, holder_mc.

holder_mc.addEventListener(MouseEvent.CLICK, onClick);

function onClick(e:MouseEvent):void {
    // do normal clicky stuff for this object
    // then..
    //

    if(canvas_mc.hitTestPoint(mouseX, mouseY, false)) {
        // do clicky stuff for canvas mc
    }    

}

Some people might say use 'getObjectsUnderPoint' but there is a documented bug with it, so use hitTestPoint() http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#hitTestPoint%28%29

九厘米的零° 2024-12-03 16:11:18

可能是您的 mask_mc 正在拦截鼠标事件。您可以尝试此测试来查看谁在触发 MouseEvent.CLICK

holder_mc.addEventListener(MouseEvent.CLICK,whoFiredTheEvent);

function whoFiredTheEvent(e:MouseEvent){
  trace(e.target.name + " fired the event");
}

如果它是 mask_mc 或其他某个影片剪辑,您可以将该影片剪辑的 mouseEnabled 设置为 false,MouseEvent 将忽略它。

It could be that your mask_mc is intercepting the mouse events. You can try this test to see who is firing the MouseEvent.CLICK.

holder_mc.addEventListener(MouseEvent.CLICK,whoFiredTheEvent);

function whoFiredTheEvent(e:MouseEvent){
  trace(e.target.name + " fired the event");
}

If it is the mask_mc or some other movie clip you can set mouseEnabled to false for that movie clip and the MouseEvent will ignore it.

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