<?xml version="1.0"?>
<!-- events/KeyboardEventPrecedence.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp();">
<mx:Script><![CDATA[
private function initApp():void {
/**
* useCapture=true 只在捕获阶段处理事件,先捕获父后捕获子
* 结果 target + currentTarget
* flex_test0.my_vbox.my_textinput.UITextField7(flex_test0): 85/117
* flex_test0.my_vbox.my_textinput.UITextField7(flex_test0.my_vbox): 85/117
* flex_test0.my_vbox.my_textinput.UITextField7(flex_test0.my_vbox.my_textinput): 85/117
*/
application.addEventListener(KeyboardEvent.KEY_UP, keyHandler,true);
my_vbox.addEventListener(KeyboardEvent.KEY_UP, keyHandler,true);
my_textinput.addEventListener(KeyboardEvent.KEY_UP, keyHandler,true);
/**
* useCapture=false(默认) 只在目标、冒泡阶段处理事件,先捕获子后捕获父
* 结果 target + currentTarget
* flex_test0.my_vbox.my_textinput.UITextField7(flex_test0.my_vbox.my_textinput): 85/117
* flex_test0.my_vbox.my_textinput.UITextField7(flex_test0.my_vbox): 85/117
* flex_test0.my_vbox.my_textinput.UITextField7(flex_test0): 85/117
*/
application.addEventListener(KeyboardEvent.KEY_UP, keyHandler);
my_vbox.addEventListener(KeyboardEvent.KEY_UP, keyHandler);
my_textinput.addEventListener(KeyboardEvent.KEY_UP, keyHandler);
my_textinput.setFocus();
}
private function keyHandler(event:KeyboardEvent):void {
ta1.text += event.target + "(" + event.currentTarget + "): " +
event.keyCode + "/" + event.charCode + "\n";
}
]]></mx:Script>
<mx:VBox id="my_vbox">
<mx:TextInput id="my_textinput"/>
</mx:VBox>
<mx:TextArea id="ta1" height="300" width="550"/>
</mx:Application>
对事件三个阶段的认识
最新推荐文章于 2022-11-24 13:59:58 发布