Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 点击以点击下方_Actionscript 3_Air - Fatal编程技术网

Actionscript 3 点击以点击下方

Actionscript 3 点击以点击下方,actionscript-3,air,Actionscript 3,Air,我有一个UIComponent,它直观地位于网格顶部,也是一个UIComponent。网格和位于顶部的UIComponent位于不同的分支上。这个女孩的孩子都是精灵。当MousEvent.CLICK被调度时,它将转到顶部的UIComponent。我想让它做的是去下面的网格元素。这可能吗 是的,你可以 如果元素id为“ui\U组件” 然后在ActionScript中,您应该添加两个属性 ui_component.mouseEnabled = true; ui_component.mouseChil

我有一个UIComponent,它直观地位于网格顶部,也是一个UIComponent。网格和位于顶部的UIComponent位于不同的分支上。这个女孩的孩子都是精灵。当MousEvent.CLICK被调度时,它将转到顶部的UIComponent。我想让它做的是去下面的网格元素。这可能吗

是的,你可以

如果元素id为“ui\U组件”

然后在ActionScript中,您应该添加两个属性

ui_component.mouseEnabled = true;
ui_component.mouseChildren = true;
这将告诉您的组件在其后面的MovieClip上传递单击事件


我希望这会有所帮助。

我所要做的只是将UIComponent置于顶部
top.mousEnabled=false
如果您的实现不允许,另一个选项是手动重新修补事件

这里有一个相当一般的例子。将以下处理程序附加到
MouseEvent。单击
将其他UIComponent或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示例相当糟糕,因为如果您事先知道所有组件,您肯定可以以不同的方式处理它。但是,如果有一组组件的位置是在运行时确定的,那么这种方法会更有意义。

它不起作用。它将继续转到位于顶部的UIComponent。我假设如果网格是位于顶部的UIComponent的一部分,那么这将起作用;not ui_component.mouseEnabled=true;