如何将多个对象拖放到特定目标?

时间:2014-04-23 10:39:51

标签: actionscript-3 flash

我是AS3的新手。当然,暂时忽略重置按钮。我知道我的代码很大而且很笨重,但我现在不介意,因为我很容易理解。

我正在尝试将黄色球与黄色球门匹配,绿色与绿色相匹配等等。

然而,每当我尝试拖动第二个对象时,我就是不能,对象被卡住,我听说AS3 / Flash存在问题,解决它的唯一简单方法是将其拖离屏幕是我不想做的事。

yellowBall.addEventListener(MouseEvent.MOUSE_DOWN, mouseDowny)
redBall.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownr)
blueBall.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownb)
greenBall.addEventListener(MouseEvent.MOUSE_DOWN, mouseDowng)
yellowBall.addEventListener(MouseEvent.MOUSE_UP, mouseUpy) 
redBall.addEventListener(MouseEvent.MOUSE_UP, mouseUpr) 
blueBall.addEventListener(MouseEvent.MOUSE_UP, mouseUpb) 
greenBall.addEventListener(MouseEvent.MOUSE_UP, mouseUpg) 
resetButton.addEventListener(MouseEvent.CLICK, reset);
addEventListener(Event.ENTER_FRAME,enterFrameHandlerr);

function mouseDowny(event:MouseEvent):void { 
 yellowBall.startDrag();
} 

function mouseDownr(event:MouseEvent):void { 
 redBall.startDrag();
} 

function mouseDownb(event:MouseEvent):void { 
 blueBall.startDrag();
} 

function mouseDowng(event:MouseEvent):void { 
 greenBall.startDrag();
} 

function mouseUpy(event:MouseEvent):void { 
 yellowBall.stopDrag();
} 

function mouseUpr(event:MouseEvent):void { 
 redBall.stopDrag();
}

function mouseUpb(event:MouseEvent):void { 
 blueBall.stopDrag();
}

function mouseUpg(event:MouseEvent):void { 
 greenBall.stopDrag();
}

function enterFrameHandlerr(event:Event):void{ 
 if(yellowBall.hitTestObject(yellowHome)){ 
 yellowBall.stopDrag();
 yellowBall.x = int(2000); 
 yellowBall.y = int(60);
 }
 if(redBall.hitTestObject(redHome)){ 
 redBall.stopDrag();
 redBall.x = int(425); 
 redBall.y = int(60);
 } 
 if(blueBall.hitTestObject(blueHome)){ 
 blueBall.stopDrag();
 blueBall.x = int(425); 
 blueBall.y = int(275);
 } 
 if(greenBall.hitTestObject(greenHome)){ 
 greenBall.stopDrag();
 greenBall.x = int(55); 
 greenBall.y = int(275);
 }
}


function reset(event:MouseEvent):void
{
 yellowBall.x = int(250); 
 yellowBall.y = int(250);   
};

0 个答案:

没有答案