这是一个拖放匹配游戏,我的问题是当我错误地匹配它时,如何阻止物品回到原来的位置?我希望这些物品留下来。请详细解释一下,我会非常感激。
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("AG8:AG16" _
), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A7:AG16")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
答案 0 :(得分:0)
您应该从每个发布函数中删除else条件。更新代码如下:
right_mc.visible=false;
wrong_mc.visible=false;
var orig1X:Number=item1_mc.x;
var orig1Y:Number=item1_mc.y;
var orig2X:Number=item2_mc.x;
var orig2Y:Number=item2_mc.y;
var orig3X:Number=item3_mc.x;
var orig3Y:Number=item3_mc.y;
item1_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
item1_mc.addEventListener(MouseEvent.MOUSE_UP, item1Release);
item2_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
item2_mc.addEventListener(MouseEvent.MOUSE_UP, item2Release);
item3_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
item3_mc.addEventListener(MouseEvent.MOUSE_UP, item3Release);
done_btn.addEventListener(MouseEvent.CLICK, checkAnswers);
reset_btn.addEventListener(MouseEvent.CLICK, reset);
item1_mc.buttonMode=true;
item2_mc.buttonMode=true;
item3_mc.buttonMode=true;
function dragTheObject(event:MouseEvent):void
{
var item:MovieClip=MovieClip(event.target);
item.startDrag();
var topPos:uint=this.numChildren-5;
this.setChildIndex(item, topPos);
}
function item1Release(event:MouseEvent):void
{
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (dropZone1_mc.hitTestPoint(item.x,item.y))
{
item.x=dropZone1_mc.x;
item.y=dropZone1_mc.y;
}
}
function item2Release(event:MouseEvent):void
{
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (dropZone2_mc.hitTestPoint(item.x,item.y))
{
item.x=dropZone2_mc.x;
item.y=dropZone2_mc.y;
}
}
function item3Release(event:MouseEvent):void
{
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (dropZone3_mc.hitTestPoint(item.x,item.y))
{
item.x=dropZone3_mc.x;
item.y=dropZone3_mc.y;
}
}
function checkAnswers(event:MouseEvent):void
{
if (dropZone1_mc.hitTestPoint(item1_mc.x,item1_mc.y) &&
dropZone2_mc.hitTestPoint(item2_mc.x,item2_mc.y) &&
dropZone3_mc.hitTestPoint(item3_mc.x,item3_mc.y))
{
wrong_mc.visible = false;
right_mc.visible = true;
}
else
{
wrong_mc.visible = true;
right_mc.visible = false;
}
}
function reset(event:MouseEvent):void {
item1_mc.x=orig1X;
item1_mc.y=orig1Y;
item2_mc.x=orig2X;
item2_mc.y=orig2Y;
item3_mc.x=orig3X;
item3_mc.y=orig3Y;
right_mc.visible=false;
wrong_mc.visible=false;
}
如果您遇到任何问题,请与我们联系。