actionscript-3airadobe-animate

Disabling mouse detection on child but remaining on parent


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?


Solution

  • So, after a bit of discussion we figured out the following:

    1. Playing with mouse directly wasn't the right way because of the display list hierarchy.
    2. The answer was in the DisplayObjectContainer.getObjectsUnderPoint(...) method that returns an Array of given DisplayObjectContainer's children and grandchildren that are directly under given point. With the use of Mouse coordinates as a point (keep in mind that you need to provide coordinates in Stage coordinate space, just like it is with hitTestPoint) you can get a list of display objects under the Mouse pointer and then handle the mouse events based on that information.

    Also along the way there was a problem of figuring the classes of the collected objects, the solution is pretty simple.

    // 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, "!!!");
            }
        }
    }