layabox 事件on的写法

class PushAdBtn extends ui.scene.pushAdBtnPanelUI
{
private img = [];
constructor()
{
super();

for(var i = 0; i < 4; i++)
{
this.img[i] = this.getChildByName("item"+i) as Laya.Image;
this.img[i].on(Laya.Event.CLICK, this, this.OnClick, [i]);//第四个传入的参数是个数组;
this.img[i].skin = "http://a.vigame.cn/xyx/lxgs_001.png"
this.img[i]["index"] = i;
}
}

OnClick(data)
{
console.log(data);//分别是0, 1 ,2 ,3;  
}
}

猜你喜欢

转载自www.cnblogs.com/StevenChancxy/p/9461856.html
今日推荐