1
votes

If my understanding of Flex is correct, skins in Flex are just DisplayObjects that are added as children to UIComponents to create the visual representation of the object. But if my understanding of the Flash event model is correct, if there is a non-transparent DisplayObject on top of another, mouse events will go to the topmost DisplayObject. The overlapped DisplayObject won't receive any mouse input.

So how is it that skinned Flex UIComponents work at all?

3

3 Answers

2
votes

As the parts in the skin are added by the component this gives it the power to ensure that you can't click on the graphics, if you look in ButtonBase class which Button extends you can see the comments that explain this:

 // DisplayObjectContainer properties.
    // Setting mouseChildren to false ensures that mouse events
    // are dispatched from the Button itself,
    // not from its skins, icons, or TextField.
    // One reason for doing this is that if you press the mouse button
    // while over the TextField and release the mouse button while over
    // a skin or icon, we want the player to dispatch a "click" event.
    // Another is that if mouseChildren were true and someone uses
    // Sprites rather than Shapes for the skins or icons,
    // then we we wouldn't get a click because the current skin or icon
    // changes between the mouseDown and the mouseUp.
    // (This doesn't happen even when mouseChildren is true if the skins
    // and icons are Shapes, because Shapes never dispatch mouse events;
    // they are dispatched from the Button in this case.)
1
votes

This page has a pretty good explanation of the eventing mechanism in Flex:

http://livedocs.adobe.com/flex/3/html/help.html?content=events_08.html

The key I believe is that MouseEvents will bubble by default. Since the skin elements are added as children of a component's display list (in "rawChildren") the event will still bubble up to the parent.

0
votes

You should still be able to add MouseEvent listeners to the host component - the best example is a skinned button. You treat it like any other button.

In a more complex skinned component though you add listeners to individual skin components in the host component. These events should bubble up to the host component as well though.