[英]How do skinned Flex UIComponents capture mouse events?
如果我对Flex的理解是正确的,则Flex中的外观只是DisplayObject,它们作为子级添加到UIComponents中,以创建对象的视觉表示。 但是,如果我对Flash事件模型的理解是正确的,并且在另一个对象之上有一个不透明的DisplayObject,则鼠标事件将转到最上面的DisplayObject。 重叠的DisplayObject将不会收到任何鼠标输入。
那么,具有外观的Flex UIComponents到底如何工作?
由于组件中添加了皮肤中的各个部分,因此可以确保您无法单击图形,如果您查看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.)
该页面很好地说明了Flex中的事件机制:
http://livedocs.adobe.com/flex/3/html/help.html?content=events_08.html
我相信关键是默认情况下MouseEvents会冒泡。 由于外观元素是作为组件显示列表的子级添加的(在“ rawChildren”中),因此事件仍会上升到父级。
您仍然应该能够将MouseEvent侦听器添加到主机组件-最好的示例是带有外观的按钮。 您可以像对待其他任何按钮一样对待它。
尽管在更复杂的外观组件中,您将侦听器添加到宿主组件中的各个外观组件。 这些事件也应该冒泡到主机组件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.