0

I add a movieclip dynamically. At some point I draw the movieclip and place the bitmap within a MC inside the MC and add an Add filter to it. Later I give Drag functionality to such parent movieclips. I want the mouse to detect everything but the drawn bitmap. I already have the movieclip that contains the bitmap set to mouseEnabled false & mouseChildren false. But the bitmap is still detected by the mouse. When I set the parent to mouseEnabled = false, the parent no longer drags, so that doesn't work. When I set the parent to mouseChildren = false, nothing changes, the bitmap is still sensed. How can I leave the drawn bitmap visible, but have the drag functionality ignore the MC-encased bitmap?

4

1 回答 1

2

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

  1. 由于显示列表层次结构,直接使用鼠标播放不是正确的方法。
  2. 答案在DisplayObjectContainer.getObjectsUnderPoint(...)方法中,该方法返回一个给定DisplayObjectContainer的直接在给定点下的子孙的数组。使用鼠标坐标作为一个点(请记住,您需要在舞台坐标空间中提供坐标,就像使用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, "!!!");
        }
    }
}
于 2019-05-14T20:08:56.503 回答