2009-07-29 136 views
1

如果我對Flex的理解是正確的,那麼Flex中的皮膚只是DisplayObject,它們作爲子元素添加到UIComponents中以創建對象的可視化表示形式。但是,如果我對Flash事件模型的理解是正確的,那麼如果在另一個頂部存在不透明的DisplayObject,則鼠標事件將轉到最上面的DisplayObject。重疊的DisplayObject將不會收到任何鼠標輸入。Skin UIComponents如何捕捉鼠標事件?

那麼剝皮的Flex UIComponents如何工作呢?

回答

0

您應該仍然可以將MouseEvent偵聽器添加到主機組件 - 最好的例子是皮膚按鈕。你像對待任何其他按鈕一樣對待它。

儘管您將偵聽器添加到主機組件中的各個皮膚組件,但它仍然是一個更復雜的蒙皮組件。儘管如此,這些事件也應該引發到主機組件。

2

由於組件添加了皮膚中的部件,因此可以確保您無法單擊圖形,如果您查看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.)