Flex Event标签
来源:互联网 发布:java jvm原理 编辑:程序博客网 时间:2024/06/11 23:16
Using the Event metadata tag
You use the [Event] metadata tag to define events dispatched by a component so that the Flex compiler can recognize
them as MXML tag attributes in an MXML file. You add the [Event] metadata tag in one of the following locations:
ActionScript components Above the class definition, but within the package definition, so that the events are bound
to the class and not a particular member of the class.
MXML components In the <mx:Metadata> tag of an MXML file.
Demo:
定义MyEvent extends Event
{
import flash.events.Event;
public class MyEvent extends Event
{
public static const EVENT_TEST:String="EventTest";
public function MyEvent(type:String,bubbles:Boolean=false,cancelable:Boolean=false)
{
super(type,bubbles, cancelable);
}
}
}
定义MyButton extends Button
<s:Button xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo"
click="dispatchEvent(new MyEvent(MyEvent.EVENT_TEST));">
<fx:Script>
<![CDATA[
import event.MyEvent;
]]>
</fx:Script>
<fx:Metadata>
<!--在Metadata标签下定义Event编译期间检查-->
[Event(name ="EventTest",type ="event.MyEvent")]
</fx:Metadata>
</s:Button>
Main App
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo"
xmlns:my="button.*"
minWidth="1024"
minHeight="768">
<fx:Script>
<![CDATA[
import event.MyEvent;
/**
* 定义Event的函数监听方式
* 在my2 的 EventTest="handleEvent(event)" 相当于对于该Event注册了一个Listiner
* 消息监听函数为handleEvent(event)
*/
private function handleEvent(e:MyEvent):void{trace(e); }
]]>
</fx:Script>
<!--可以直接定义EventTest="myTa.text='got Event';" 及在Event触发式执行myTa.text='got Event';-->
<my:MyButton id="my1" EventTest="myTa.text='got Event';"x="208" y="213"></my:MyButton>
<my:MyButton id="my2" EventTest="handleEvent(event)"x="209" y="258"></my:MyButton>
<s:TextArea id="myTa" x="141"y="55"/>
</s:Application>
解释:
1· 在MyButton中将[Event]标签放入Metadata标签中,则告诉编译器该空间会产生该种Event,
如果此时dispatchEvent出去的Event不是该种类型 则在编译期间及会报错。
2· 在主类中<my:MyButton id="my1" EventTest="myTa.text='got Event';" x="208" y="213"></my:MyButton>
由于EventTest已经在Metadata做了标记,即可使用代码提示功能找到相应的Event。
EventTest="myTa.text='got Event';" 表示为EventTest 这个Event注册一个监听者,监听到信息后处理方式为
myTa.text='got Event' , same as the EventTest="handleEvent(event)
- Flex Event标签
- flex event标签
- Flex元数据标签之[Event]
- Flex的Event对象
- Flex Event Tips
- Flex Event 顺序
- Learning Flex - Event
- Flex Event总结
- flex event实例
- Flex Event总结
- Flex Event事件机制
- flex的event
- Flex Event总结
- Flex effect /event
- Event 标签的运用
- 关于FLEX的event,token,
- Flex or JS Event Flow
- Flex分享:Event事件机制
- 为什么需要htons(), ntohl(), ntohs(),htons() 函数 .模拟htonl、ntohl、htons、ntohs函数实现
- Dev C++ 开源免费集成开发环境
- linux的运行级别 /etc/inittab
- sql中一些常用的函数
- vb/vb.net开发精粹(13)
- Flex Event标签
- iphone开发每日一练【2011-11-2】
- android开发技术文章荟萃【2011-11-2】
- 英雄的黎明
- 未来市场前景极其可观的室内GPS
- C# 字典表出现重复疑问
- SQL拆分函數
- OOM解决
- linux进程状态及转换关系