AS3:目标与currentTarget之间的差异 [英] AS3: Difference between target vs currentTarget
问题描述
Possible Duplicate:
Difference between e.target and e.currentTarget
我不太了解这两者之间的区别
I don't really understand the difference between these two
event.target and
event.CurrentTarget and explanation.
有人可以通过一个简单的例子向我解释吗?
Can somebody explain this to me on a simple example?
推荐答案
假设您创建了TextInput
对象.
import fl.controls.TextInput;
import flash.events.MouseEvent;
var t:TextInput;
function init():void {
t = new TextInput();
t.x = 100;
t.y = 100;
t.width=100;
t.height=30;
t.addEventListener(MouseEvent.CLICK, fresult);
this.addChild(t);
}
function fresult(e:Event):void {
trace(e.target);
trace(e.currentTarget);
}
init();
单击TextInput可以得到以下痕迹:
Clicking on the TextInput gives the trace of:
[对象TextField]
[对象TextInput]
[object TextField]
[object TextInput]
这意味着:
event.target
是事件起源的对象.也就是说,在这种情况下,点击了TextField,因此事件起源于TextField
.
event.target
is the object from which the event originated. i.e. in this case, a TextField was clicked on, so the event originated from the TextField
.
event.currentTarget
是调用侦听器的对象.在这种情况下,TextInput
称为侦听器,因此currentTarget
是TextInput
event.currentTarget
is the object which called the listener. In this case, the TextInput
called the listener, so the currentTarget
is TextInput
这篇关于AS3:目标与currentTarget之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!