博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Flex 事件机制
阅读量:6935 次
发布时间:2019-06-27

本文共 2270 字,大约阅读时间需要 7 分钟。

事件是所有交互式应用的基础,人机对话需要通过事件机制来完成,Flex应用程序能够为用户提供绝佳的使用体验,就必须要有完善的事件机制作为各种交互的基础。Flex事件机制遵守W3C标准--Document Object Model(DOM) Level 3 Events Specification Version 1.0,具体请参考:

    1.事件响应过程
    和其他语言时间处理机制不同,除了应用传统监听者设计模式来注册事件的监听外,Flex事件还分为三阶段--Capturing、Targeting、Bubbling,来应对更复杂场景的事件响应需求,根据Flex官方文档,对于三者的描述分别为:
    About the capturing phase
    The first part of the event flow is called the capturing phase. This phase comprises all of the nodes from the root node to the parent of the target node. During this phase, Flash Player examines each node, starting with the root, to see if it has a listener registered to handle the event. If it does, Flash Player sets the appropriate values of the Event object and then calls that listener. Flash Player stops after it reaches the target node's parent and calls any listeners registered on the parent.
    About the targeting phase
    The second part of the event flow, the targeting phase, consists solely of the target node. Flash Player sets the appropriate values on the Event object, checks the target node for registered event listeners, and then calls those listeners.
    About the bubbling phase
    The third part of the event flow, the bubbling phase, comprises all of the nodes from the target node's parent to the root node. Starting with the target node's parent, Flash Player sets the appropriate values on the Event object and then calls event listeners on each of these nodes. Flash Player stops after calling any listeners on the root node.
用文档中的插图来描述整个过程:
    Capturing阶段处理的对象是Stage和Parent,Targeting处理的对象是Child1和Child2,Bubbling针对Parent和Stage,并且按照顺序进行,这样就可以在不同的阶段去处理不同的事情,设计出结构更好的事件代码。
    2.target和currentTarget
    target指向事件的发起者,或为事件的调度对象,由谁产生这一系列的事件,target就指向谁,currentTarget为当前正在处理事件的结点,感觉就像是事件的两种this指针,跟踪事件的发展过程。举个更具体的例子,技术总监有一项任务,交给技术经理完成,技术经理将该任务分配给具体的技术工程师,技术工程师在执行该任务时,target指向技术总监,crrentTarget指向该技术工程师。
    3.事件停止
    stopPropagation和stopImmediatePropagation是停止事件处理的两个方法,两者的区别有点类似于循环中的continue和break,前者允许当前结点对象所有事件执行完毕后,再停止事件向前发展,后者直接停止所有事件。
    4.系统事件
    Flex事件分为用户事件和系统事件,前者存在于预定义好的组件之中,后者有两个重要的方法:Initialize和CreationComplete,在组件创建时调用。
    Initialize
    Fires before determines appearance
    Can use to set appearance properties
    CreationComplete
    Fires after measurement and layout
    Can use if code relies on appearance
    Fires after objects are created and ready for use

转载地址:http://lapjl.baihongyu.com/

你可能感兴趣的文章
为app添加动态gif背景
查看>>
括号配对问题1
查看>>
Xamarin开发Android笔记:TextView行间距设定
查看>>
div间的小红点,可能是BOM头,利用ultraedit另存为UTF-8无BOM即可
查看>>
如何利用altera 给出的megafunction配置成自己想要的FIFO和RAM ——本文为转载
查看>>
熟悉常用的Linux操作
查看>>
如何用java实现数据脱敏
查看>>
html5 本地存储有多少种方案:
查看>>
Access-Control-Max-Age是什么?
查看>>
Extjs文件上传问题总结
查看>>
C# 导出Excel的示例(转)
查看>>
NUC1014 排版题.输出排列成菱形的字母
查看>>
利用反射机制获取属性的值遇到的坑
查看>>
最新app源码下载:200款优秀Android项目源码
查看>>
PHP/Yii2操作Cookie,常见问题以及注意事项
查看>>
支持向量机(五)SMO算法
查看>>
编译Android源码
查看>>
聚类分析算法---学习
查看>>
通过SQL Server命令行启动及停止SQL服务的方法
查看>>
笔记本电脑不显示电量图标-20180103
查看>>