import flash.events.MouseEvent;
import flash.geom.Point;
//假如你有两个元件A与B,都是两个显示容器。以下是伪代码。
var bW:Number = B.width;
var bH:Number = B.height;
var dis:Number;
var pointA:Point = new Point(A.x,A.y);
var pointB:Point = new Point(B.x,B.y);
A.addEventListener(MouseEvent.MOUSE_DOWN,onDow);
A.addEventListener(MouseEvent.MOUSE_UP,onUp);
function onDow(evt:MouseEvent):void
{
evt.currentTarget.startDrag(true);
}
function onUp(evt:MouseEvent):void
{
evt.currentTarget.stopDrag();
mX = evt.currentTarget.x - B.x;
mY = evt.currentTarget.y - B.y;
pointA.x = evt.currentTarget.x;
pointA.y = evt.currentTarget.y;
dis = Point.distance(pointA,piontB);
if (dis<bW||dis<bH)
{
evt.currentTarget.x = B.x;
evt.currentTarget.y = B.y;
B.addChild(A);
evt.currentTarget.removeEventListener(MouseEvent.MOUSE_DOWN,onDow);
evt.currentTarget.removeEventListener(MouseEvent.MOUSE_DOWN,onUp);
A.play();
}
}