在何处监听POPUP派发的事件

 Buble up Events向上传播的冒泡事件

In Adobe Flex it is easy to make a event bubble, which means that if a DisplayObject dispatches an event, the event will be re-dispatched by each parent of the DisplayObject until it reaches the root of the application.

This behavior is really useful.  One common function that I use this behavior for is handling the navigation within my applications.  I attach an event listener to the singleton application instance (Application.application) for navigation events, and handle them within the main application class.  This means that any control, anywhere in the application, can easily navigate to any other part of the application through one line of code ( dispatchEvent( new NavivationEvent(….) ).

大家都知道Event是沿着对象的继承树向上传播的,这部分就是讲这是个相当好的特性,当然是很好的特性,我们所有的人大概都爱死这个特性了,看看我们的作者碰到了什么问题.

The Problem问题
Bubbling events dispatched from popups within the Flex application are not heard by a listener attached to the application instance.  This is

 从弹出框派发的事件无法被添加在application对象的监听器捕获。

because DisplayObjects created through the PopupManager.createPopup() function are not children of the application container. How then, can

 因为,从PopupManager.createPopup() 创建的显示对象DisplayObjects 不是application的子类,按照冒泡事件特性,当然添加在application对象的监听器就没法捕获此事件了

 we cleanly handle events coming out of popups so that we still only have one pattern for handling navigation within the application?

 

The Solution
To solve this problem, we need to know a little bit about the structure of a Flex application as shown in the diagram below:

要解决这个问题,我们需要了解一些FLEX的框架,如下图所示:

Flex Application Structure

In this diagram we can clearly see that popups within a Flex application are not children of the application container, but are instead children of the SystemManger. 从这张图,我们可以清楚的看出,FLEX应用程序的弹出框不是application容器的子类,而是systemmananger的子类

I wont go into the functions of the system manager here, but every UIComponent contains a reference to the system manager of the current application so its easy to get a reference to it. 当然我在这里不会详述任何系统的函数,但是必须指出,每一个UICOMPONENT都包含了一个到当前SYSMANAGER的引用,因此很容易就能得到当前SYSMANAGER的引用。

This means that instead of attaching my event listener to:这意味着我们可以这样的挂接一个监听器
Application.application (不是这儿)

I can instead attach my listener to:挂接到这儿
Application.application.systemManager 挂接到这儿

Then my listener will hear all bubbling events within the system, regardless of whether they originate within a Popup or a standard UIComponent.

Problem solved. 这样在POPUP里冒泡出的事件就能被监听到了。

 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值