首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

事件优先级小结

2012-11-01 
事件优先级总结package event{import flash.events.Eventimport spark.components.Button[Event(namet

事件优先级总结

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>


测试输出结果:
EventPriorityApp.demo4EventPriorityButton.demo2EventPriorityButton.demo1EventPriorityApp.demo3EventPriorityApp.test4EventPriorityButton.test1EventPriorityButton.test2EventPriorityApp.test3


测试总结:
优先级对同一类型事件有效,对不同类型事件无效,虽然test4优先级20000高于demo4优先级10000,但是先派发demo事件,所有demo4还是先执行了事件类型相同优先级相同的话谁先注册就先执行谁

热点排行