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

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

问题描述

可能的重复:
e.target 和 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 对象.

Suppose you create a TextInput object.

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:

[对象文本字段]
[对象文本输入]

[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:目标与当前目标之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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