Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.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/1/typo3/2.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
Apache flex Flex中自定义组件中的冒泡事件_Apache Flex - Fatal编程技术网

Apache flex Flex中自定义组件中的冒泡事件

Apache flex Flex中自定义组件中的冒泡事件,apache-flex,Apache Flex,我正在flex mxml应用程序文件的另一个自定义组件中使用自定义组件。是否可以将事件从内部组件冒泡到外部组件并处理外部组件中的事件?//outer.mxml //Outer.mxml <local:Inner id="inner"/> inner.addEventListener(TYPE_NAME, handler); private function handler(e:Event):void { trace("Bingo"); } //Inner.mxml disp

我正在flex mxml应用程序文件的另一个自定义组件中使用自定义组件。是否可以将事件从内部组件冒泡到外部组件并处理外部组件中的事件?

//outer.mxml
//Outer.mxml
<local:Inner id="inner"/>
inner.addEventListener(TYPE_NAME, handler);
private function handler(e:Event):void
{
    trace("Bingo");
}

//Inner.mxml
dispatchEvent(new Event(TYPE_NAME));
addEventListener(类型\名称,处理程序); 私有函数处理程序(e:事件):void { 跟踪(“宾果”); } //Inner.mxml dispatchEvent(新事件(类型_名称));
//Outer.mxml
addEventListener(类型\名称,处理程序);
私有函数处理程序(e:事件):void
{
跟踪(“宾果”);
}
//Inner.mxml
dispatchEvent(新事件(类型_名称));

是只要在分派时将属性
bubbles
设置为true到内部组件中:

内部组件:

dispatchEvent(new Event("myEvent", true));
addEventListener("myEvent", onMyEvent);
...
外部组件:

dispatchEvent(new Event("myEvent", true));
addEventListener("myEvent", onMyEvent);
...

是,在分派时,只需将内部组件的属性
bubbles
设置为true:

内部组件:

dispatchEvent(new Event("myEvent", true));
addEventListener("myEvent", onMyEvent);
...
外部组件:

dispatchEvent(new Event("myEvent", true));
addEventListener("myEvent", onMyEvent);
...
构造函数将
bubbles
参数默认为
false
,因此,如上所述,在构造事件时,需要将
bubbles
设置为
true

启用冒泡后,事件将继续在UI树上调度,直到调用或为止

但是请记住,冒泡只会影响UI组件;从自定义类触发的事件不会冒泡,即使
冒泡
参数设置为
true
构造函数将
冒泡
参数默认为
false
,因此,如上所述,在构造事件时需要将
冒泡
设置为
true

启用冒泡后,事件将继续在UI树上调度,直到调用或为止

但是请记住,冒泡只会影响UI组件;从自定义类激发的事件不会冒泡,即使
冒泡
参数设置为
true