Search code examples
actionscript-3functionframeadditionmovieclip

Play MovieClip frame by frame in addition after same function is executed several times


I have a MovieClip named fails_mc, it consists of 3 soccer balls and in my game every time my player fails I need to add an X mark over 1 ball, I have a hitTestObject detecting when the ball hits the goal area, but when the ball goes outside I need to play 1 frame inside the fails_mc and add the X mark to a ball ( I have 3 different png files inside fails_mc, 1 on each frame), this is the code I’m using but I don’t know how to play frame by frame the fails_mc (keep in mind that the same function will be used every time, that’s why each frame must be added to the last played frame:

if (ball.hitTestObject(goalie))
{
    goal_mc.play();
    net_mc.play();
}
else
{
    fails_mc.play(+=1); // This is not working

    trace("It’s a fail");
}

After 3 fails I must trigger another function that will finish the game but I will figure out how to do that later on.


Solution

  • I think all your looking for is the nextFrame() function of a movieClip.

    you could also use gotoAndStop("x1") - where "x1" is the frame label (or number if not in quotes) you want the movieClip to goto. You could use a variable to track the current state.

    var misses:int = 0;
    
    if (ball.hitTestObject(goalie))
    {
    
        goal_mc.play();
        net_mc.play();
    
    }
    else
    {
        misses++;
        trace("It’s a fail");
    
        if(misses > 3){
            //do your game over stuff
        }else{
            fails_mc.gotoAndStop(misses)
        }
    }