[知识点]
1、复制用for循环
2、便于操作单个精灵var newsprite:Sprite=event.target as Sprite
3、移到最前再次addChild()
[效果]
[代码]
1、复制用for循环
2、便于操作单个精灵var newsprite:Sprite=event.target as Sprite
3、移到最前再次addChild()
[效果]
拖动移到最前(for).swf
(2008-12-14 19:03:13, Size: 825 B , Downloads: 1)
[代码]
CODE:
for (var k:uint=0; k<8; k++) {
//利用for循环画8个正方形
var A:Sprite=new Sprite();
A.graphics.lineStyle(1);
A.graphics.beginFill(0xBBBBBB);
A.graphics.drawRect(0,0,50,50);
A.graphics.endFill();
addChild(A);
//排列正方形
A.x=uint(k%4)*100+50;
A.y=uint(k/4)*100+50;
//在每个正方形中插入动态文本
var txt:TextField=new TextField();
txt.autoSize=TextFieldAutoSize.LEFT;
A.addChild(txt);
txt.text="第"+(k+1)+"个";
//鼠标移上正方形时显示手形
txt.mouseEnabled=false;
A.buttonMode=true;
//添加侦听事件
A.addEventListener(MouseEvent.MOUSE_DOWN,ax);
A.addEventListener(MouseEvent.MOUSE_UP,sk);
}
//按下开始拖动
function ax(event:Event) {
//便于操作单个精灵,如果直接拖动A则只对最后一个起作用
var B:Sprite=event.target as Sprite;
B.startDrag();
//将拖动的精灵移到最前
addChild(B);
}
//松开停止拖动
function sk(event:Event) {
stopDrag();
}