views:

61

answers:

3

I hope I explain this well. But in my game I have 3 keyframes for my bullet Movieclip. 1 to display its normal state. 2 to show it Blown Up, and 3 to remove it from the stage. A total of 3 frames. When the bullet hits an object, I go to and play the 2nd frame. then when frame 3 hits, I remove it. Here is my code

private function blowUp():void
        {
            if(dead)
            {
                gotoAndPlay(2);
                if(currentFrame == 3)
                {
                    garbage = true;
                }
            }
        }

My problem is it goes to frame 2 but never reaches frame three. so frame 3 can not garbage collect the bullet. If I use Play() instead then it works, but gotoAndPlay doesnt

I even tried to remove the keyframe from frame 3(it is still a frame). (Hoping it would play through) but it doesn't. I know my problem is dumb, so if anyone can help , that would be great. thanks

+2  A: 

Are you sure you are not calling blowUp every frame and so you are resetting to frame 2 all the time ?

If is the case, perhaps, try to put a boolean guard:

    private var doingBlowUp : Boolean = false;

    private function blowUp() : void
    {
        if (dead) {
            if (doingBlowUp)
            {
                if (currentFrame == 3)
                {
                    garbage = true;
                    doingBlowUp = false;
                }

            } else {
                doingBlowUp = true;
                gotoAndPlay(2);
            }
        }

    }
Patrick
A: 

You would have to add an enter frame event handler. Try tracing currentFrame where you are doing the logic to see if it is == 3. My guess is that it will be a value of two. The other option would be to call a function from frame 3 to do the appropriate clean up.

Chris Gutierrez
A: 

Watch out for the bug in Flash Player 9, where gotoAndPlay(x) would play frame "x" twice.

Richard Inglis