Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/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 从flexGlobals.topLevelApplication获取内部组件_Actionscript 3_Apache Flex_Flex4 - Fatal编程技术网

Actionscript 3 从flexGlobals.topLevelApplication获取内部组件

Actionscript 3 从flexGlobals.topLevelApplication获取内部组件,actionscript-3,apache-flex,flex4,Actionscript 3,Apache Flex,Flex4,我觉得访问内部组件的方式比我所知道的要好。 我知道我们可以访问任何内部组件,例如: FlexGlobals.topLevelApplication.someChild1.someChild2.someChild3…等等 我有一个组件,它有许多父组件层次结构。我想知道我是否可以访问最后一个孩子,而无需提及其所有家长 我需要在该组件上触发一个事件 FlexGlobals.topLevelApplication.child1.child2.child3.dispatchEvent(new Event(

我觉得访问内部组件的方式比我所知道的要好。 我知道我们可以访问任何内部组件,例如: FlexGlobals.topLevelApplication.someChild1.someChild2.someChild3…等等

我有一个组件,它有许多父组件层次结构。我想知道我是否可以访问最后一个孩子,而无需提及其所有家长

我需要在该组件上触发一个事件

FlexGlobals.topLevelApplication.child1.child2.child3.dispatchEvent(new Event('clearData', true));
更新:我尝试了你在第1点中建议的方法。我已经在子组件上添加了事件侦听器,并尝试从动作脚本文件中分派它,但它没有被听到\

child3.addEventLisener('clearData', clearHandler);
然后我将事件发送到如下位置:

dispatchEvent(new Event(modelApp.CLEAR_PALETTE, true)

我认为您应该深入到组件级别,并在初始化时添加EventListener。 从你想去的任何地方发送

另一种方法是,您需要在creationComplete上的对象中保存组件引用(ID)。在模型中保存其参照。现在,您可以随时随地访问它。你想干什么就干什么

我也这样做了,我将屏幕组件引用保存在一个数组中,并在需要动态验证所有组件的地方访问它

否则,您需要嵌套循环来获取所需的子对象。

尝试添加

FlexGlobals.topLevelApplication.systemManger.addEventLisener('clearData', clearHandler);
儿童3

把它从你想要的任何地方拿出来

对于调度,请使用以下命令

FlexGlobals.topLevelApplication.systemManager.dispatchEvent(new Event(modelApp.CLEAR_PALETTE, true)

我是如何理解这个问题的,没有使用好的应用程序设计原则,但这是另一个问题
在您的情况下,您可以使用阶段作为气泡事件的全局currentTarget。从displayObject分派事件,气泡=true;在目标显示对象中,使用带有/不带捕获阶段的阶段对象侦听事件

在任何displayObject中:

dispatchEvent(new Event("myEvent", true));
// add ADDED_TO_STAGE event listener in constructor or when component creation complete
protected function component_creationCompleteHandler(event:FlexEvent):void
{
    addEventListener(Event.ADDED_TO_STAGE, onAddToStage);
}

..

protected function onAddToStage(event:Event):void
{
    stage.addEventListener("myEvent", eventHandler, true);
}

protected function eventHandler(event:Event):void
{
    trace("eventHandler");
}
在目标displayObject中:

dispatchEvent(new Event("myEvent", true));
// add ADDED_TO_STAGE event listener in constructor or when component creation complete
protected function component_creationCompleteHandler(event:FlexEvent):void
{
    addEventListener(Event.ADDED_TO_STAGE, onAddToStage);
}

..

protected function onAddToStage(event:Event):void
{
    stage.addEventListener("myEvent", eventHandler, true);
}

protected function eventHandler(event:Event):void
{
    trace("eventHandler");
}
这比引用FlexGlobals对象要好。代码更加灵活