-1

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 );
}
paup
  • 23
  • 5
  • Share your actual source code. It can work the way you want so likely this issue is how you're laying the items and where you're attaching your mouse listeners. – BadFeelingAboutThis Jun 16 '14 at 20:36
  • Though I'm curious why the graphic is layered on top of the shape? - and by shape I'm assuming it's not actually a `Shape` object (which can't receive click events) but a Sprite or MovieClip? – BadFeelingAboutThis Jun 16 '14 at 20:40
  • The "Territory Shape" is a MovieClip with manually drawn (in the Flash IDE) vector shapes in it. – paup Jun 16 '14 at 20:50
  • Per request I added a sample of the code. I hope that helps. – paup Jun 16 '14 at 20:56
  • I have a single MouseEvent listener added to the stage. (I use event.target to discern which territory has been clicked) I presumed this was preferable over having 750 mouse event listeners. The reason the shape is below the graphic is because the graphic should be visible, not the shape. If I set the shape to invisible it can no longer be clicked. – paup Jun 16 '14 at 21:06
  • You forgot the addEventListener in your sample. – Nambew Jun 16 '14 at 21:08
  • WorldMapContainer.addEventListener( MouseEvent.MOUSE_DOWN, m_MouseEventHandler.onMouseDown ); – paup Jun 16 '14 at 21:13
  • You can set your shape's alpha to 0, then it can still be clicked. Perhaps it's slightly more efficient though the way you are trying (though it also may not be). Show the code for your `onMouseDown` function. It would arguably be cleaner to have the mouse listeners on the shapes directly. If they all inherit from the same base class it you would only need to write it once. – BadFeelingAboutThis Jun 16 '14 at 22:05
  • Wouldn't that give performance issues? We're talking 750 additional mouse listeners, and I couldn't even remove the one I have now as I need it for panning. – paup Jun 17 '14 at 16:38

1 Answers1

-1

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

Lukasz 'Severiaan' Grela
  • 6,078
  • 7
  • 43
  • 79
  • Looks like the solution was in this line of thinking. I forgot to set the "Set of Territories" Container to mouseEnabled = false. Thus this one was registering the click! – paup Jun 17 '14 at 16:55