2011-10-10 22 views
1

我有一個UIComponent,坐在網格的頂部視覺上,這也是一個UIComponent。網格和位於頂部的UIComponent位於不同的分支上。網格有孩子,是精靈。當MousEvent.CLICK派發時,它將轉到頂層的UIComponent。我想要它做的是去下面的網格元素。這可能嗎?點擊擊中底下

回答

1

我所要做的就是隻是做在上面top.mousEnabled = false

1

當然可以,

,如果你的元素ID爲「ui_component」

然後在ActionScript中,您應該增加兩個屬性

ui_component.mouseEnabled = true; 
ui_component.mouseChildren = true; 

這會告訴你的分量通過點擊影片剪輯事件在它後面。

我希望這會有所幫助。

+0

它沒有工作。它繼續去視覺上的UIComponent。如果網格是位於頂層的UIComponent的一部分,我認爲這會起作用。 – NebulaFox

+0

你需要ui_component.mouseEnabled = false;不是ui_component.mouseEnabled = 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示例相當糟糕,因爲如果您事先知道所有組件,那麼您肯定可以以不同的方式處理這些組件。但是,如果你有一堆組件的位置是在運行時確定的,這樣做會更有意義。