Event的target和currentTarget的区别
发布网友
发布时间:2022-04-29 13:23
我来回答
共1个回答
热心网友
时间:2022-04-23 23:16
简单说,target是事件的调用对象(event dispatcher),currentTarget是事件的处理对象(event processor)
示例:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="" layout="vertical" name="app"
initialize="init()">
<mx:Button id="btn" name="btn" label="按钮1"/>
<mx:Button id="btn2" name="btn2" label="按钮2" click="clickHandler(event)" />
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function init(): void
{
addEventListener(MouseEvent.CLICK, clickHandler);
}
private function clickHandler(event: MouseEvent): void
{
Alert.show("target: " + (event.target as DisplayObject).name
+ "\ncurrentTarget: " + (event.currentTarget as DisplayObject).name);
}
]]>
</mx:Script>
</mx:Application>