我正在使用AS3创建一个拖放游戏。这是我用来拖放的代码。游戏将为用户提供提示,其中用户必须将三个选项中的特定答案拖动到正确的位置。该编码将允许用户选择所有三个选项。我想要做的是限制用户选择多个选项。有人可以帮我这个吗?
var myArray:Array = [apple, grapes, gava];
var matchImage:Array = [imgApple, imgGrapes, imgGuava];
var posArray:Array = [ {x:55.3, y:55.6}, {x:100.45, y:100.6}, {x:300.5, y:250.7} ];
var currentClip:MovieClip;
var Xpos:Number;
var Ypos:Number;
for(var i:int = 0; i < wordArray.length; i++) {
myArray[i].buttonMode = true;
myArray[i].addEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown);
}
function item_onMouseDown(event:MouseEvent):void {
currentClip = MovieClip(event.currentTarget);
Xpos = currentClip.x;
Ypos = currentClip.y;
addChild(currentClip);
currentClip.startDrag();
stage.addEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp);
}
function stage_onMouseUp(event:MouseEvent):void {
stage.removeEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp);
currentClip.stopDrag();
var index:int = myArray.indexOf(thisClip);
var equalClip:MovieClip = MovieClip(matchImage[index]);
if(matchImage.hitTestPoint(thisClip.x, thisClip.y, true)) {
currentClip.x = posArray[index].x;
currentClip.y = posArray[index].y;
currentClip.removeEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown);
currentClip.buttonMode = false;
}
else
{
currentClip.x = startXposition;
currentClip.y = startYposition;
}
}
答案 0 :(得分:1)
在任何剪辑上检测到MouseEvent.MOUSE_DOWN后,您应该删除其他剪辑上的侦听器,这样可以防止它们被拖动。
完成拖动操作后,您可以将其添加回来以允许用户再次开始拖动。