-1
我正在創建一個帶有hittestobject的拖放遊戲,但是當按下後退按鈕時,拖放遊戲的標籤仍然顯示在背框上。按下後退按鈕之前是否必須重置遊戲?如何阻止hittestobject進入另一個框架? FLASH AS3
代碼:
right_mc.visible=false;
wrong_mc.visible=false;
var orig1X:Number=frog_mc.x;
var orig1Y:Number=frog_mc.y;
var orig2X:Number=queen_mc.x;
var orig2Y:Number=queen_mc.y;
var orig3X:Number=apple_mc.x;
var orig3Y:Number=apple_mc.y;
frog_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
frog_mc.addEventListener(MouseEvent.MOUSE_UP, frog_mcRelease);
queen_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
queen_mc.addEventListener(MouseEvent.MOUSE_UP, queen_mcRelease);
apple_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
apple_mc.addEventListener(MouseEvent.MOUSE_UP, apple_mcRelease);
done_btn.addEventListener(MouseEvent.CLICK, checkAnswers);
reset_btn.addEventListener(MouseEvent.CLICK, reset);
frog_mc.buttonMode=true;
queen_mc.buttonMode=true;
apple_mc.buttonMode=true;
function dragTheObject(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
item.startDrag();
var topPos:uint=this.numChildren-1;
this.setChildIndex(item, topPos);
}
function frog_mcRelease(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (drop_frog.hitTestPoint(item.x,item.y)) {
item.x=drop_frog.x;
item.y=drop_frog.y;
} else {
item.x=orig1X;
item.y=orig1Y;
}
};
function queen_mcRelease(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (drop_queen.hitTestPoint(item.x,item.y)) {
item.x=drop_queen.x;
item.y=drop_queen.y;
} else {
item.x=orig2X;
item.y=orig2Y;
}
};
function apple_mcRelease(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (drop_apple.hitTestPoint(item.x,item.y)) {
item.x=drop_apple.x;
item.y=drop_apple.y;
} else {
item.x=orig3X;
item.y=orig3Y;
}
};
function checkAnswers(event:MouseEvent):void {
if (drop_frog.hitTestPoint(frog_mc.x,frog_mc.y) &&
drop_queen.hitTestPoint(queen_mc.x,queen_mc.y) &&
drop_apple.hitTestPoint(apple_mc.x,apple_mc.y)) {
wrong_mc.visible = false;
right_mc.visible = true;
} else {
wrong_mc.visible = true;
right_mc.visible = false;
}
}
function reset(event:MouseEvent):void {
frog_mc.x=orig1X;
frog_mc.y=orig1Y;
queen_mc.x=orig2X;
queen_mc.y=orig2Y;
apple_mc.x=orig3X;
apple_mc.y=orig3Y;
right_mc.visible=false;
wrong_mc.visible=false;
}