Skip to main content
Participating Frequently
February 14, 2011
Question

Restart movieclip after hittest

  • February 14, 2011
  • 1 reply
  • 1020 views

Hi all

I have recently started to learn about flash and as2 and I am working on a small shooting style game.

I have managed to create a hero that moves around the screen and enemies which I shoot at.

The issue I am currently having is that on my ball movieclip (bullett) the first frame holds a ball

and the 2nd frame is a small animation of the ball breaking apart. So basically when the ball is thrown

and the hittest comes back true the 2nd frame plays showing ball breaking apart. Now when I fire a 2nd time

it constatly plays the 2nd frame of the broken ball. How can I resart the ball movieclip in its 1st frame to carry

on shooting normally. Below is the as2 I have on my ball movie clip.

onClipEvent (load) {
    var statee;
    statee = "ready";
    maxJump = -30;
    grav = 0;
    gravity = 1.5;
    rotate = true;


}
onClipEvent (enterFrame) {
   if (Key.isDown(Key.SPACE)) {
        statee = "position";
    }
    if (statee == "position") {
        this._x = _root.hero._x;
       this._y = _root.hero._y;
        statee = "fire";
        grav = maxJump;
    }
    if (statee == "fire") {
        grav += gravity;
       this._y += grav;
       this._x += 10;
    }

    if (this.hitTest(_root.enemy)) {
       this.gotoAndStop(2);
       
        rotate = false;
       this._rotation = 0;

    }
   
    if (rotate) {
       this._rotation += 10;
    }

}

Many thanks for all help and advice.

Rock

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
February 14, 2011

If the intention is to have the break apart animation play out, then you can probably just have the ball movieclip reset itself to frame 1 via the end of the animation. (maybe something to the effect of _parent.gotoAndStop(1) at the end of the animation timeline).

rockwarAuthor
Participating Frequently
February 14, 2011

Hi Ned

thanks for your reply.

This did'nt work. What I am aiming for is the ball to be thrown and when it hits an enemy it will play the 2nd frame of the ball

movieclip which is of the ball breaking apart. When the ball is thrown again I want to play the first frame of the ball movieclip

but instead I keep getting the 2nd frame of the ball breaking apart.

I have been doing some research but cant find a definative answer I think the problem is in the hittest as you can see the as2

I have put on the ball movieclip plays frame 2 after the hit, I then need the movieclip to restart from 1 to throw a full ball again.

}

    if (this.hitTest(_root.enemy)) {
        this.gotoAndStop(2);
        rotate = false;
        this._rotation = 0;
    }

Thanks again-Rock

Ned Murphy
Legend
February 14, 2011

What I told you should work, so however you implemented it is probably why it doesn't.