3
我一直在創建一個Flash文件,其中可以在舞臺上拖動和移動多個MovieClip。我已經設置了功能來控制它被拖動的時間,但是當我點擊一個MovieClip時,另一個立即將自己附着到另一個。我如何解決這個問題?Actionscript 3.0一次拖動一個MovieClip
下面是代碼:
import flash.geom.Point;
//Add variables and items, such as milk and eggs to stage:
var milkClickOffset:Point = null;
var eggClickOffset:Point = null;
var milk:Milk = new Milk();
milk.x = 250;
milk.y = 250;
addChild(milk);
var egg:Egg = new Egg();
egg.x = 330;
egg.y = 330;
addChild(egg);
//Milk Event listeners:;
addEventListener(MouseEvent.MOUSE_DOWN, startMilkDrag);
addEventListener(MouseEvent.MOUSE_UP, stopMilkDrag);
addEventListener(Event.ENTER_FRAME, dragMilk);
//Egg Event listeners:
addEventListener(MouseEvent.MOUSE_DOWN, startEggDrag);
addEventListener(MouseEvent.MOUSE_UP, stopEggDrag);
addEventListener(Event.ENTER_FRAME, dragEgg);
//Milk Functions:;
function startMilkDrag(event:MouseEvent):void
{
milkClickOffset = new Point(event.localX,event.localY);
}
function stopMilkDrag(event:MouseEvent):void
{
milkClickOffset = null;
}
function dragMilk(event:Event):void
{
if (milkClickOffset != null)
{// must be dragging
milk.x = mouseX - milkClickOffset.x;
milk.y = mouseY - milkClickOffset.y;
}
}
//Egg Functions:
function startEggDrag(event:MouseEvent):void
{
eggClickOffset = new Point(event.localX,event.localY);
}
function stopEggDrag(event:MouseEvent):void
{
eggClickOffset = null;
}
function dragEgg(event:Event):void
{
if (eggClickOffset != null)
{// must be dragging
egg.x = mouseX - eggClickOffset.x;
egg.y = mouseY - eggClickOffset.y;
}
}
是,就是這樣,非常感謝。 – 2012-03-13 16:14:15