Ending the game when healthbar drops to zero

So I’m trying to end my little “something falls down, gotta catch it or else” game when the player’s healthbar drops to zero. The healthbar is a movieclip that is 80 pixels wide and 10 pixels high. If a bad thing falls to the ground you lose health.

I’ve written a code to the actions-layer on frame 3 like this:

healthp = 4; //the default amount of health when health is full
hpPercent = _root.healthp/4; //this counts the percent on how much there is health
this.health._width = hpPercent*80; //times 80 because the bar is 80 pixels wide

to substract health, I’ve written (I’ve ripped some of the falling snow tutorial)

if (this, hitTest(_root.ground)) {
_root.healthp = _root.healthp - 1;
this._x = -10+Math.random()*movieWidth;
this._y = -5;
}

that code is on the bad thing that you should not let fall down, you should catch it.

Then I’ve written

if (_root.healthp == 0) {
gotoAndPlay(4);
}

and tried to put it almost everywhere but it doesn’t react at all to any of the happenings.

How can I make this work. I’ve got multiple layers on this flash, the first two frames are for the preloader, the third frame is for the game, and this script (if it worked) would go to frame 4 when the healthbar would drop to zero. I have a rectangular movie clip named as health and I’ve assigned it a variable called health.

If you folks know a better way to make an energy meter and make the game end then please share it with me :slight_smile: