皮肤Flex UIComponents如何捕获鼠标事件?

时间:2009-07-29 03:23:19

标签: flex flash actionscript-3

如果我对Flex的理解是正确的,那么Flex中的皮肤只是作为子对象添加到UIComponent中的DisplayObject,以创建对象的可视化表示。但是,如果我对Flash事件模型的理解是正确的,如果在另一个上面有一个非透明的DisplayObject,鼠标事件将转到最顶层的DisplayObject。重叠的DisplayObject将不会接收任何鼠标输入。

那么皮肤Flex UIComponents是如何工作的呢?

3 个答案:

答案 0 :(得分:2)

由于组件添加了皮肤中的部件,因此它可以确保您无法单击图形,如果查看Button扩展的ButtonBase类,您可以看到解释此内容的注释: / p>

 // 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 :(得分:1)

此页面对Flex中的事件机制有很好的解释:

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

我认为关键是MouseEvents默认会冒泡。由于外观元素是作为组件显示列表的子元素添加的(在“rawChildren”中),因此事件仍会冒泡到父级。

答案 2 :(得分:0)

您仍然可以将MouseEvent侦听器添加到主机组件 - 最好的示例是蒙皮按钮。你把它视为任何其他按钮。

在更复杂的蒙皮组件中,您可以将侦听器添加到主机组件中的各个外观组件。这些事件也应该冒泡到主机组件中。