Reputation: 2212
I have a menu that is a sprite and I'm adding a button to be able to minimize the menu. I'm using a SimpleButton()
and I added the button as a child of the menu so menu.addChild(button)
The problem I'm having is that when I mouse over and click the button none of the events are firing. The menu sprite has its own mouse over event and the button should be placed relative to the menu so it makes sense to be a child of the menu. How can I make the button still work?
Thanks in advance!
Edit
Here is my code:
protected const rectangle:Sprite = new Sprite();
private const minimizeBtn:SimpleButton = new SimpleButton(new ButtonDisplayState(MINIMIZE_BTN_BG_COLOR, 15, 15), new ButtonDisplayState(0xFF0000, 15, 15), new ButtonDisplayState(0x00FF00, 15, 15), new ButtonDisplayState(0x0FF000, 15, 15));
rectangle.addEventListener(MouseEvent.MOUSE_OVER, rectMouseOver);
addChild(rectangle);
rectangle.addChild(minimizeBtn);
Upvotes: 0
Views: 1087
Reputation:
First of all, why the heck are you defining your button as a const? Define it as a non-const variable that's just silly unless you have a REALLY good reason for it. Second, add your event listeners DIRECTLY to the minimizeBtn, not the rectangle container (the parent object).
Also be aware that although the documentation says that the four states of the button are optional in the constructor, they really are not optional at all. The class is very specific about the constructor parameters which will cause the class to break and not function correctly at runtime (without compile or runtime errors of course, since flash is the champion of that).
So although you are providing all four constructor arguments here, it may be something to tinker with if my previous suggestions fail. See the following link for more NFO about the constructor.
http://selfdocumentingcode.blogspot.com/2009/04/flash-simplebutton-and-mouseover-and.html
Upvotes: 0
Reputation: 6641
The parent sprite (menu) may be eating the mouse events. Try setting mouseChildren = true on that object.
Upvotes: 1