事件优先级总结


package event
{
import flash.events.Event;

import spark.components.Button;

[Event(name="test", type="flash.events.Event")]
[Event(name="demo", type="flash.events.Event")]

public class EventPriorityButton extends Button
{
public function EventPriorityButton()
{
super();
this.addEventListener("test", test1);
this.addEventListener("test", test2);
this.addEventListener("demo", demo2);
this.addEventListener("demo", demo1);
}

private function test1(event:Event):void
{
trace("EventPriorityButton.test1");
}

private function test2(event:Event):void
{
trace("EventPriorityButton.test2");
}

private function demo1(event:Event):void
{
trace("EventPriorityButton.demo1");
}

private function demo2(event:Event):void
{
trace("EventPriorityButton.demo2");
}
}
}



<?xml version="1.0" encoding="utf-8"?>
<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/mx"
minWidth="955"
minHeight="600"
xmlns:event="event.*"
creationComplete="eventPriorityTestApp_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;

protected function eventPriorityTestApp_creationCompleteHandler(event:FlexEvent):void
{
eventPriorityTestButton.addEventListener("test", test3);
eventPriorityTestButton.addEventListener("test", test4, false, 20000);
eventPriorityTestButton.addEventListener("demo", demo3);
eventPriorityTestButton.addEventListener("demo", demo4, false, 10000);
}

protected function eventPriorityTestButton_clickHandler(event:MouseEvent):void
{
eventPriorityTestButton.dispatchEvent(new Event("demo"));
eventPriorityTestButton.dispatchEvent(new Event("test"));
}

protected function test3(event:Event):void
{
trace("EventPriorityApp.test3");
}

protected function test4(event:Event):void
{
trace("EventPriorityApp.test4");
}

protected function demo3(event:Event):void
{
trace("EventPriorityApp.demo3");
}

protected function demo4(event:Event):void
{
trace("EventPriorityApp.demo4");
}
]]>
</fx:Script>
<event:EventPriorityButton id="eventPriorityTestButton"
label="事件优先级测试"
click="eventPriorityTestButton_clickHandler(event)"/>
</s:Application>


◇[b]测试输出结果:[/b]
[list]
[*]EventPriorityApp.demo4
[*]EventPriorityButton.demo2
[*]EventPriorityButton.demo1
[*]EventPriorityApp.demo3
[*]EventPriorityApp.test4
[*]EventPriorityButton.test1
[*]EventPriorityButton.test2
[*]EventPriorityApp.test3
[/list]


◇[b]测试总结:[/b]
[list]
[*]优先级对同一类型事件有效,对不同类型事件无效,虽然test4优先级20000高于demo4优先级10000,但是先派发demo事件,所有demo4还是先执行了
[*]事件类型相同优先级相同的话谁先注册就先执行谁
[/list]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值