如何在as3上停止功能

时间:2015-12-25 22:51:01

标签: actionscript-3 flash

嗯......我试图停止在as3上编码的动画,但不能这样做。代码!

//this make the ground move
function GroundAndEndingMove(event:Event):void
{   
    ground.x = ground.x - 5;
    if (ground.x <= -846.24)
    {
        ground.x = -846.25;
        ending.x = 503.5;
        stop();

    }
    stopmation.x = stopmation.x - 5;
    if (stopmation.x <= -846.24)    
    {
        ground.x = -846.25;
        ending.x = 503.5;
        stop();
    }
    ending.x = ending.x - 5.1;
    if (ending.x <= 503.5)

    {
        rowl.x = 548.1;
        ending.x = 503.5;
        stop();
    }
    trash.x = trash.x - 5.1;
    if (trash.x <= 503.5)
    {   
        trash.x = 503.5;
        ball.x = ball.x + 5.1;
        stop();
    }

}
stage.addEventListener(Event.ENTER_FRAME, GroundAndEndingMove);

//this function make the ball to faled

function GameOver(event:Event):void
{
    if(ball.hitTestObject(ground))
    {
        //here I should stop the animation wherever it be.
    }
    if (ball.hitTestObject(stopmation))
    {
        //also here
    }

}
stage.addEventListener(Event.ENTER_FRAME, GameOver);

怎么办?或者你有更好的主意.. 救命啊!

(抱歉任何拼写错误......我很久以前就做过这件事,现在又回到了它。)

2 个答案:

答案 0 :(得分:0)

我不知道它是否对您有所帮助,但无论如何..尝试从舞台stage.removeEventListener(Event.ENTER_FRAME, GameOver);删除事件监听器

答案 1 :(得分:0)

这是一个简单的逻辑 - 你几乎就在那里。

首先考虑伪代码,不要陷入“编程”

    if (A is true OR B is true) then
    // end game: do cleanup etc.
    // off user some option (new game, etc)
    end if
function GameOver(event:Event):void
{
    if(ball.hitTestObject(ground) || ball.hitTestObject(stopmation))
    {
     stage.removeEventListener(Event.ENTER_FRAME, GroundAndEndingMove);
     stage.removeEventListener(Event.ENTER_FRAME, GameOver);

     // all cleaned up: what happens now?
    }
}