Monday, April 9, 2007


1. Why won't my component register mouse events?
  1. For mouse events to fire, the mouseEnabled property of the object must equal true.
  2. If a parent of your component has mouseChildren set to false, none of the children will receive the mouse events.
  3. Children receive mouseEnabled events before there parents and have the opportunity to halt these events by calling event.stopPropagation() or event.stopImmediatePropagation(). In this case your component will never hear the mouse event. The easiest way to test for this is to set mouseChildrenEnabled to false because then the children will not process the event and will not have an opportunity to halt it. If the event fires after doing this, one of the children is halting the event.
  4. The mouse must be over the hit area of the component for an event to fire. By default, the hit area consists of all of the drawn pixels in the component, not the rectangular bounds of the component. To redefine the hit area without changing the appearance, you can either set the hitArea property or you can draw transparent pixels using the Graphics class:,0); // set graphics to draw transparent pixels,0,component.width,component.height); // draw transparent pixels over entirety of component
  5. It is possible that a "shield" component is in front of the intended mouse target. If the "shield" component has mouseEnabled = true and has transparently drawn pixels as explained in answer 4 above, this component will intercept the mouse events.

1 comment:

Anonymous said...

Really useful tips! Basic things like this are sometimes hard to find in the regular docs when you are developing custom components, or want to inherit from low-level classes. Thanks for this straightforward and practical information.

"Flex", "ActionScript" and possibly "MXML" are probably trademarks of Adobe Systems Incorporated.
"Adobe" is a trademark of Adobe Systems Incorporated.
This site is in no way endorsed or sponsored by Adobe Systems Incorporated.
Content Copyright © 2007 Daniel Freiman.
Site Design Copyright by its copyright holder.
The Flex Non-Docs reserves the right to remove comments for any reason.
All ActionScript and MXML code (and ONLY ActionScript and MXML code) on this website is available under the MIT License.