Search code examples
actionscript-3flashactionscriptmouseeventflash-cs6

MouseInput ignored when having multiple overlapping items on mouseEnabled = false


I'm running into problems with mouseEvents not being fired when multiple elements which aren't mouseEnabled are on top of the element that I try to click.

In the game I'm building I have a board similar to the board game "Risk". So I have territories with a irregular shape.

My visual scene is as follows:

WorldMap
-Set of Territories owned by player
--Territory
---Territory graphic
---Territory shape

So each territory has two children, the graphic is a MovieClip with a PNG graphic. This MovieClip is set to both mouseEnabled and mouseChildren = false. It has to be because being a bitmap it's square rather than irregularly shaped.

Previously I did not have the bitmaps in place and I could simply select each territory by clicking the different shapes, but now that I've added the bitmaps as an additional child, each territory has an apparent rectangular bounding box. When clicking inside the shape of a territory the territory is selected as expected. But when clicking outside the shape, but inside the bounding box nothing happens at all, instead of clicking through the PNG and into the underlying shape of another territory, the whole mouse input is ignored.

It's as if 2 overlapping PNGs which aren't mouse enabled is too much for Flash to handle??

Is this a known problem? Am I doing something wrong? Is there a workaround?

Code sample

public function Territory( a_TerritoryXML:XML )
{
    var t_ClassReference:Class          = Main.Instance.LibTerritories.applicationDomain.getDefinition( a_TerritoryXML.tname ) as Class;
    m_TerritoryShape                    = new t_ClassReference();
    m_TerritoryShape.x                  = a_TerritoryXML.xPos;
    m_TerritoryShape.y                  = a_TerritoryXML.yPos;
    m_TerritoryShape.mouseEnabled       = true;
    m_TerritoryShape.mouseChildren      = true;
    mouseEnabled                        = false;
    mouseChildren                       = true;
    t_ClassReference                    = Main.Instance.LibTerritories.applicationDomain.getDefinition( a_TerritoryXML.tname + "Graphic" ) as Class;
    var t_TerritoryGraphic:MovieClip    = new t_ClassReference();
    t_TerritoryGraphic.x                = a_TerritoryXML.xPos;
    t_TerritoryGraphic.y                = a_TerritoryXML.yPos;
    t_TerritoryGraphic.mouseEnabled     = false;
    t_TerritoryGraphic.mouseChildren    = false;
    this.addChild( t_Graphic );
    this.addChildAt( m_TerritoryGraphic, 0 );
}

Solution

  • Sometimes mouseEnabled=false; is just not enough, try adding also mouseChildren=false;.