- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
教你7步实现flex自定义Event及参数传递
Flex应用开发过程中如需要灵活的在不同组件(如A与B,父与子)之间响应事件,传递参数等功能时就会使用自定义事件(Event)机制,下面通过一个事例分七步,通过自定义Event和EventDispatcher两种机制实现事件交互和参数传递;??????? 事例描述: 有一个父亲“parentApp.mxml”有两个儿子“comBrotherA.mxml”和comBrotherB.mxml,新年 降至,两个儿子为表孝心分别给他们老爸存入(事件)一笔过节费(事件参数),并通知老爸我存钱进去了,老爸在收到两个儿子的钱后汇总后同时告诉(事件)两 个儿子钱我已收到总数(事件参数)是多少...??? 1、第一步:引入自定义注册事件参数传递扩展类(来自网络)???
view plaincopy to clipboardprint?
package?myeventhelper??
{??
????//自定义注册事件参数传递扩展类??
????public?class?EventArgExtend??
????{??
????????public?function?EventArgExtend()??
????????{??
????????}??
????????public?static?function?create(f:Function,...arg):Function?//动态参数创建??
????????{??
????????????var?F:Boolean?=?false;??
????????????var?_f:Function?=?function(e:*,..._arg)??
????????????{??
????????????????_arg?=?arg;??
????????????????if(!F)??
????????????????{??
????????????????????F?=?true;??
????????????????????_arg.unshift(e);??
????????????????}??
????????????????f.apply(null,_arg);??
????????????};??
????????????return?_f;??
????????}??
????????public?static?function?toString():String??
????????{??
????????????return?Class?JEventDelegate;??
????????}??
????}??
}??
??? 2、第二步:自定义事件触发类:
view plaincopy to clipboardprint?
package?myeventhelper??
{??
????import?flash.events.EventDispatcher;??
?????
????import?mx.core.UIComponent;??
????//自定义事件触发类??
????public?class?MyEventDispatcher?extends?EventDispatcher??
????{??
????????private?static?var?_instance:MyEventDispatcher;??
????????public?static?const?EXEC_PARENT_METHOD:String=ExecParentMethod;?//执行Parent方法??
????????public?static?function?getInstance():MyEventDispatcher??
????????{??
???????????if(_instance==null){??
??????????????_instance=new?MyEventDispatcher();??
???????????}??
???????????return?_instance;??
????????}??
????????public?var?Source:UIComponent;?//事件源对象??
????????public?var?Parsms:Object;?//主要用于参数传递??
????}??
}??
??? 3、第三步:用户自定义事件类???
view plaincopy to clipboardprint?
package?myeventhelper??
????{??
????????import?mx.events.FlexEvent;??
????????//用
文档评论(0)