-1

我正在创建一个带有 hittestobject 的拖放游戏,但是当按下后退按钮时,拖放游戏的标签仍然显示在后帧上。我必须在按下返回按钮之前重置游戏吗?

代码:

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; 
}
4

1 回答 1

0

理想情况下,您需要在返回时删除所有 eventListener。如果您通过另一个的 addChild 命令添加了一些孩子,您必须删除聊天孩子。您是如何将“拖放游戏的标签”添加到屏幕上的?

于 2013-03-05T15:25:54.447 回答