我有一個UIComponent,坐在網格的頂部視覺上,這也是一個UIComponent。網格和位於頂部的UIComponent位於不同的分支上。網格有孩子,是精靈。當MousEvent.CLICK派發時,它將轉到頂層的UIComponent。我想要它做的是去下面的網格元素。這可能嗎?點擊擊中底下
Q
點擊擊中底下
1
A
回答
1
我所要做的就是隻是做在上面top.mousEnabled = false
1
當然可以,
,如果你的元素ID爲「ui_component」
然後在ActionScript中,您應該增加兩個屬性
ui_component.mouseEnabled = true;
ui_component.mouseChildren = true;
這會告訴你的分量通過點擊影片剪輯事件在它後面。
我希望這會有所幫助。
1
另一種選擇的UIComponent,如果您的實現不允許你disable the mouse events for the top UIComponent,是手動重新分派該事件。
下面是一個相當普遍的例子。附上用於MouseEvent.CLICK
以下處理程序或者保持該其它的UIComponents或在頂部上UIComponent的一個容器:
private function propagateClickEvent(event:MouseEvent):void
{
// find all objects under the click location
var uicOver:Array = getObjectsUnderPoint(new Point(event.stageX, event.stageY));
// filter out what you don't want; in this case, I'm keeping only UIComponents
uicOver = uicOver.filter(isUIComponent);
// resolve skins to parent components
uicOver = uicOver.map(resolveSkinsToParents);
// remove the current item (otherwise this function will exec twice)
if (event.currentTarget != event.target) { // otherwise let the following line do the removal
uicOver.splice(uicOver.indexOf(event.currentTarget),1);
}
// remove the dispatching item (don't want to click it twice)
uicOver.splice(uicOver.indexOf(event.target),1);
// dispatch a click for everything else
for each (var uic:UIComponent in uicOver) {
uic.dispatchEvent(new MouseEvent(MouseEvent.CLICK, false)); // no bubbling!
}
}
// test if array item is a UIComponent
private function isUIComponent(item:*, index:int, arr:Array):Boolean {
return item is UIComponent;
}
// resolve Skins to parent components
private function resolveSkinsToParents(item:*, index:int, arr:Array):* {
if (item is Skin) {
return item.parent;
}
return item;
}
此代碼將工作爲MXML如下:
<s:Group click="propagateClickEvent(event)">
<s:Button click="trace('button1')"/>
<s:Button click="trace('button2')"/>
<s:Button click="trace('button3')"/>
</s:Group>
<!-- trace output on click: "button3", "button1", "button2" -->
這是非常通用。我建議使用比UIComponent
更具體的內容,否則它可能會派遣更多的點擊次數。這完全取決於你實際在做什麼。另外,MXML示例相當糟糕,因爲如果您事先知道所有組件,那麼您肯定可以以不同的方式處理這些組件。但是,如果你有一堆組件的位置是在運行時確定的,這樣做會更有意義。
相關問題
- 1. UIView底部不可點擊
- 2. 點擊Windows移動射擊中的絕對DIV點擊底層元素
- 3. 點擊兩個鏈接,點擊一下
- 4. 如何使底層div不可點擊?
- 5. UITableView的底部是不可點擊的
- 6. 差( '點擊' 和.off( '點擊')。在( '點擊'
- 7. 單擊窗體不點擊底層控制
- 8. 如何使底下的元素不可點擊/停用?
- 9. jQuery下拉菜單點擊可點擊(第二次點擊)父母
- 10. 通過點擊/點擊Jquery中的刪除點擊類?
- 11. jquery - 點擊下拉菜單
- 12. 下一個點擊鍵按
- 13. bootstrap下拉只能點擊
- 14. 下拉通過點擊
- 15. Powershell點擊下載Javavascript:__ doPostBack
- 16. 點擊下拉列表QComboBox
- 17. 無法點擊下拉
- 18. 菜單點擊下拉JS
- 19. 創建點擊下拉框
- 20. 點擊下拉菜單
- 21. 向下滾動點擊
- 22. jquery點擊展開下來
- 23. 下載圖片點擊wordpress
- 24. 點擊JQuery下一課
- 25. CSS3下拉轉換點擊
- 26. 點擊下載按鈕
- 27. highcharts android點擊幾下?
- 28. 點擊下一個元素
- 29. ASHX圖像點擊下載
- 30. 點擊下一步DIV
它沒有工作。它繼續去視覺上的UIComponent。如果網格是位於頂層的UIComponent的一部分,我認爲這會起作用。 – NebulaFox
你需要ui_component.mouseEnabled = false;不是ui_component.mouseEnabled = true; –