[]三个图好像无法绑定不同的事件?

Laya.init(400, 400, laya.webgl.WebGL);

var img1 = new Laya.Sprite();
img1.loadImage('https://layaair.ldc.layabox.com/demo/h5/res/apes/monkey2.png',100,100,90,90);
Laya.stage.addChild(img1);
img1.on(Laya.Event.CLICK,this, function(name){ console.log(name);},['图1']);

var img2 = new Laya.Sprite();
img2.loadImage('https://layaair.ldc.layabox.com/demo/h5/res/apes/monkey2.png',200,300,90,90);
Laya.stage.addChild(img2);
img2.on(Laya.Event.CLICK,this, function(name){ console.log(name);},['图2']);

var img3 = new Laya.Sprite();
img3.loadImage('https://layaair.ldc.layabox.com/demo/h5/res/apes/monkey2.png',300,300,90,90);
Laya.stage.addChild(img3);
img3.on(Laya.Event.CLICK,this, function(name){ console.log(name);},['图3']);

我这样给三个图绑定点击事件,为什么无论点哪个图console.log显示的都是 图3 ?
已邀请:

赞同来自:

你那个层级有问题的!赏金给我吧
var img1:Sprite = new Sprite;
img1.mouseThrough = true;
img1.loadImage('https://layaair.ldc.layabox.com/demo/h5/res/apes/monkey2.png', 100, 100, 90, 90);
Laya.stage.addChild(img1);
 
img1.on(Laya.Event.CLICK, this, function(name)
{
console.log(name);
}, ['图1']);
 
var img2:Sprite = new Sprite();
img2.mouseThrough = true;
img2.loadImage('https://layaair.ldc.layabox.com/demo/h5/res/apes/monkey2.png', 200, 300, 90, 90);
Laya.stage.addChild(img2);
img2.on(Laya.Event.CLICK, this, function(name)
{
console.log(name);
}, ['图2']);
 
var img3:Sprite = new Sprite();
img3.mouseThrough = true;
img3.loadImage('https://layaair.ldc.layabox.com/demo/h5/res/apes/monkey2.png', 300, 300, 90, 90);
Laya.stage.addChild(img3);
img3.on(Laya.Event.CLICK, this, function(name)
{
console.log(name);
}, ['图3']);

Aar0n

赞同来自:

把demo传上来看看吧。

该问题目前已经被锁定, 无法添加新回复

商务合作
商务合作