如果我对Flex的理解是正确的,那么Flex中的皮肤就是作为子级添加到UIComponents中以创建对象的可视化表示的DisplayObjects。但是如果我对Flash事件模型的理解是正确的,如果在另一个之上有一个不透明的DisplayObject,鼠标事件将会转到最上面的DisplayObject。重叠的DisplayObject不会接收任何鼠标输入。
那么,带皮肤的Flex UIComponents到底是如何工作的呢?
发布于 2009-07-29 05:25:12
这个页面很好地解释了Flex中的事件机制:
http://livedocs.adobe.com/flex/3/html/help.html?content=events_08.html
我认为关键是MouseEvents默认情况下会出现泡沫。由于皮肤元素是作为组件显示列表(在“rawChildren”中)的子元素添加的,因此事件仍然会冒泡到父元素。
发布于 2010-11-22 23:32:42
由于皮肤中的部分是由组件添加的,因此它具有确保您不能单击图形的功能,如果您查看Button扩展的ButtonBase类,您可以看到解释这一点的注释:
// 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.)发布于 2010-02-07 17:54:59
您应该仍然能够将MouseEvent侦听器添加到主机组件-最好的示例是带皮肤的按钮。您可以像对待任何其他按钮一样对待它。
但是,在更复杂的皮肤组件中,需要向宿主组件中的各个皮肤组件添加侦听器。但是,这些事件也应该冒泡到主机组件。
https://stackoverflow.com/questions/1197903
复制相似问题