<?xml version="1.0"?> <!-- events/ShowEventPriorities.mxml --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()"> <mx:Script><![CDATA[ private function returnResult(e:Event):void { ta1.text += "returnResult() method called last (priority 1)\n"; } private function verifyInputData(e:Event):void { ta1.text += "verifyInputData() method called first (priority 3)\n"; } private function saveInputData(e:Event):void { ta1.text += "saveInputData() method called second (priority 2)\n"; } private function initApp():void { b1.addEventListener(MouseEvent.CLICK, returnResult, false, 1); b1.addEventListener(MouseEvent.CLICK, saveInputData, false, 2); b1.addEventListener(MouseEvent.CLICK, verifyInputData, false, 3); } ]]></mx:Script> <mx:Button id="b1" label="Click Me"/> <mx:TextArea id="ta1" height="200" width="300"/> </mx:Application>
b1.addEventListener(MouseEvent.CLICK, returnResult, false, 1);
这里的第三个参数是事件的优先级,这里表示鼠标点击会有三个事件来响应,响应的顺序根据第三个参数设定,越高越先执行,这里点击后三个事件的执行顺序为verifyInputData,saveInputData,returnResult