2011-10-10 51 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示例相当糟糕,因为如果您事先知道所有组件,那么您肯定可以以不同的方式处理这些组件。但是,如果你有一堆组件的位置是在运行时确定的,这样做会更有意义。