AS3:目标与currentTarget之间的差异 [英] AS3: Difference between target vs currentTarget

查看:106
本文介绍了AS3:目标与currentTarget之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
e.target和e.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称为侦听器,因此currentTargetTextInput

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆