[]循环添加一组按钮事件无法正常使用
循环添加啦一组按钮,但是按钮事件无法正常执行,单独给文本添加啦同一组事件,可以正常执行
private function addEgg():void
{
trace("addEgg");
for(var i:int = 0; i<eggLoc.length; i++)
{
//trace(eggLoc[i][1]+" "+eggLoc[i][0]);
var yy0 = eggLoc[i][1]/2;
var yy1 = parseInt(eggLoc[i][1]/2);
var tx;
var ty;
eggHoleWidth = 83;
eggHoleHeight = 83;
if(yy0 == yy1)
{
tx = dx + eggLoc[i][0]*eggHoleWidth;
}
else
{
tx = dx + eggLoc[i][0]*eggHoleWidth + floatX;
}
ty = dy + eggLoc[i][1]*eggHoleHeight;
//checkLoc[eggLoc[i][0]][eggLoc[i][1]]= 1;
var b:Sprite = new Sprite();
//var c = this.getChildByName("eggHole"+[eggLoc[i][0]+eggLoc[i][1]);
b.graphics.drawTexture(Laya.loader.getRes(Res),tx-45,ty-45);
b.size(92,96);
b.name = "egg"+i;
Laya.stage.addChild(b);
b.on(Event.MOUSE_DOWN, this, mouseHandler);
b.on(Event.MOUSE_MOVE, this, mouseHandler);
b.on(Event.MOUSE_UP, this, mouseHandler);
trace("addEvent");
}
}
private function mouseHandler(e:Event=null)
{
trace("mouseEvent");
trace("e "+e.target);
switch (e.type)
{
case Event.MOUSE_DOWN:
trace("press");
e.target.startDrag();
break;
case Event.MOUSE_MOVE:
trace("move");
break;
case Event.MOUSE_UP:
trace("release")
e.target.stopDrag();
break;
}
}
没有找到相关结果
已邀请:
3 个回复
cuixueying
赞同来自: anlijames
anlijames
赞同来自:
anlijames
赞同来自: