如何阻止hittestobject进入另一帧? FLASH AS3

时间:2013-03-05 14:55:00

标签: actionscript-3 flash

我正在创建一个带有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; 
}

1 个答案:

答案 0 :(得分:0)

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