flex4学习笔记_events
发布时间:2020-12-15 01:26:35 所属栏目:百科 来源:网络整理
导读:Summary for events in flex4 (英语摘自原文,这个貌似只适合我自己看。。。)? In this chapter,I described the Flex event architecture and how you can create your own events to share data between application components. You learned the followin
Summary for events in flex4 (英语摘自原文,这个貌似只适合我自己看。。。)?
In this chapter,I described the Flex event architecture and how you can create your own events to
share data between application components. You learned the following:
?
●?a Flex applications are event-driven.
?
●?Every component that dispatches events includes EventDispatcher in its inheritance?hierarchy.
?
●?You handle events with either MXML-based event handlers or the addEventListener() method.
?? ?调用event的处理函数一般有两种方式(MXML-based & AS),比如
<components:LoginForm login=”loginHandler(event)”/>
等同于
myForm.addEventListener(LoginEvent.LOGIN,loginHandler); //LoginEvent.LOGIN就是String("login")
?? ?这里的login对应于自定义组件LoginForm中的元数据声明
<fx:Metadata>
[Event(name=”login”,type=”events.LoginEvent”)]
</fx:Metadata>
?? ?类似的,Button也是一个组件,click就对应于login
<s:Button id="myButton" label="Click me" click="clickHandler(event)">
?或者 myButton.addEventListener(MouseEvent.CLICK,clickHandler);
//这里clickHanlder不需要参数
?
?
●?Event handler functions receive a single event argument and return void.
?
●?Flash Builder 4 adds the capability to generate event handler functions for all Flex components?and events.
?? ?这点确实好用,bible这本书上有详细的介绍
?
●?You can declare and dispatch custom events from your custom components.
?
●?You can create custom event classes to store and send data from custom components to?the rest of the application.
?? ?在我看来,这点比较适用于数据交换、传递。在组件内监听一个事件,进行一些处理,把结果保存在event的属性上,比如event.text,在组件外可以通过handler function把这个属性传递给其他的组件属性。
?
●?To make a custom event class bubble,set its bubbles property to true.
?? ?在我的理解,各个“容器”“从小到大”,依次响应event,比如click(如果设有handler function)
?
●?Override the Event class’s clone() method if you want to be able to re-dispatch custom?event objects from an event handler method.
?? ?这点不知道实际用途有哪些。。。
?
●?You handle custom events and event classes with the same architecture as pre-built classes?that are included in the Flex SDK.
?? ?这个就如同上面的类比
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |