在子级上禁用鼠标检测,但在父级上保留鼠标

时间:2019-05-14 05:20:29

标签: actionscript-3 air adobe-animate

我动态添加了动画片段。有时,我会绘制动画片段并将位图放置在MC内的MC中,并向其中添加“添加”滤镜。稍后,我将“拖动”功能赋予此类父影片剪辑。我希望鼠标检测除绘制的位图以外的所有内容。我已经有包含位图设置为mouseEnabled false和mouseChildren false的动画片段。但是,鼠标仍然可以检测到位图。当我将父级设置为mouseEnabled = false时,父级不再拖动,因此不起作用。当我将父级设置为mouseChildren = false时,什么都没有改变,位图仍然被检测到。如何使绘制的位图保持可见状态,但使拖动功能忽略MC封装的位图?

1 个答案:

答案 0 :(得分:2)

因此,经过一番讨论,我们得出以下结论:

  1. 由于显示列表的层次结构,直接玩鼠标是不正确的方法。
  2. 答案是在DisplayObjectContainer.getObjectsUnderPoint(...)方法中,该方法返回直接位于给定点以下的给定 DisplayObjectContainer 的子代和子代的 Array 。使用鼠标坐标作为点(请记住,您需要在 Stage 坐标空间中提供坐标,就像 hitTestPoint 一样) >),您可以在鼠标指针下获取显示对象的列表,然后根据该信息处理鼠标事件。

在解决收集对象的类的过程中,解决方案也非常简单。

// We are in the root here.
addEventListener(MouseEvent.MOUSE_DOWN, onDown);

function onDown(e:MouseEvent):void
{
    var aPoint:Point = localToGlobal(new Point(mouseX, mouseY));
    var aList:Array = getObjectsUnderPoint(aPoint);

    // Lets browse through all the results.
    for each (var aChild:DisplayObject in aList)
    {
        // How to find if an object is an instance of certain Class.
        if (aChild is Shape)
        {
            trace("A Shape was found under a name of", aChild.name, "!!!");
        }
    }
}