fllash as 3.0对象拖动效果
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:MouseEvent):void {
//便于操作单个精灵,如果直接拖动A则只对最后一个起作用
var B:Sprite=event.target as Sprite;
B.startDrag();
//将拖动的精灵移到最前
addChild(B);
}
//松开停止拖动
function sk(event:MouseEvent):void {
stopDrag();
}
补充:flash教程,As3.0