在何处监听POPUP派发的事件

翻译 2007年09月24日 22:48:00

 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里冒泡出的事件就能被监听到了。

 

事件派发,监听

using System; using System.Collections.Generic; using System.Linq; using System.Text;public class Ev...

cocos2d-js 自定义事件监听派发

熟悉js的dom事件或者flash事件的,基本都能立马明白cc.eventManager的用法。 cc.eventManager有两种注册监听器的方式,一种是原生事件,例如 cc.ev...

cocos2d-js 自定义事件监听派发

熟悉js的dom事件或者flash事件的,基本都能立马明白cc.eventManager的用法。 cc.eventManager有两种注册监听器的方式,一种是原生事件,例如 cc.even...

android事件派发验证demo

  • 2015年12月27日 15:02
  • 2.57MB
  • 下载

cocos2d-x v3.0 事件派发机制

于cocos2d-x v3.0alpha0加入 http://blog.csdn.net/huang_hws/article/details/18554749 介绍 cocos2d-x ...

Android触摸屏事件派发机制详解与源码分析一(View篇)

PS一句:最终还是选择CSDN来整理发表这几年的知识点,该文章平行迁移到CSDN。因为CSDN也支持MarkDown语法了,牛逼啊!【工匠若水 http://blog.csdn.net/yanbobe...
  • yanbober
  • yanbober
  • 2015年05月21日 17:03
  • 48215

Unity3D事件派发机制之Delegate

上一章:【基于MONO事件派发机制之SendMessage】 废话不多说,直接上代码。 [mw_shl_code=csharp,true]/* * NotificationDelegCenter ...

inputmanager对按键事件的获取和向上派发

在Android系统中,键盘按键事件是由WindowManagerService服务来管理的,然后再以消息的形式来分发给应用程序处理,不过和普通消息不一样,它是由硬件中断触发的;在上一篇文章《Andr...

Android View触摸屏事件派发机制详解与源码分析

1 背景 最近在简书和微博还有Q群看见很多人说Android自定义控件(View/ViewGroup)如何学习?为啥那么难?其实答案很简单:“基础不牢,地动山摇。” 不扯蛋了,进入正题。就算你不自...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:在何处监听POPUP派发的事件
举报原因:
原因补充:

(最多只允许输入30个字)