我有 2 个对象和 1 个目标。我将在鼠标键按下时拖动一个对象,并在鼠标键向上并且对象位于目标之一时放下它。当 o2 在目标中并将 o1 拖到目标上时,o2 会回到它的位置,而不是 o1 不会到达目标。
有人可以帮助我吗?
var t1:int=0; //target is empty
o1.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
o1.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
function startDragging(evt:MouseEvent):void
{
o1.startDrag();
if (o1.x == tar1.x && o1.y == tar1.y)
{
t1 = 0;
}
}
function stopDragging(evt:MouseEvent ):void
{
if (tar1.hitTestObject(o1) && t1 == 0)
{
o1.x = tar1.x;
o1.y = tar1.y;
o1.stopDrag();
t1 = 1; //target is full
}
else
{
o1.x = 250;
o1.y = 200;
o1.stopDrag();
}
}
o2.addEventListener(MouseEvent.MOUSE_DOWN, startDragging2);
o2.addEventListener(MouseEvent.MOUSE_UP, stopDragging2);
function startDragging2(evt:MouseEvent):void
{
o2.startDrag();
if (o2.x == tar1.x && o2.y == tar1.y)
{
t1 = 0;
}
}
function stopDragging2(evt:MouseEvent ):void
{
if (tar1.hitTestObject(o2) && t1 == 0)
{
o2.x = tar1.x;
o2.y = tar1.y;
o2.stopDrag();
t1 = 1;}
else
{
o2.x = 250;
o2.y = 140;
o2.stopDrag();
}
}