Health like in energy? You don't know how to use variables and _xscale?
//Starting value Health = 100;
//Put this inside a loop EnergyBar._xscale = Health;
_xscale works with percentages, so 100 equals the full bar, and it will get smaller whenever you subtract from the variable. It's imperative that it's in a Loop like onEnterFrame, or else it would run only once, and wouldn't update the value
You can do the level thing with global variables. To make a variable global just put _global. in front of it
Midmenj, I'd recommend that you learn the concept of variables and constants before proceeding to a task such as making a game. I'll explain the code and the concept of variables a bit here...
The word 'Health' is a variable. Pretty much anything can be a variable (or var). A variable in programming is exactly like a variable in mathematics...it is a letter/word that can have values that change. You are making 'Health' a variable since this is going to change as you play the game. I presume what you are trying to make is a game in which the character's health goes down as he hits something or something hits him. So you need to make a hit test. The code will be structured sorta like this:
If hittest(whatever condition) = true { Health -= Health - 10; EnergyBar._xscale = Health; }
Also, you will need a health bar with the instance name of EnergyBar for this to work. And, this code will go in the main timeline...
If you don't understand hit test, plz google it...I would explain it to you but i gtg...
I do have to comment on the code from jpx111... I'm pretty sure it's just a typo, but I'd hate for you to use it and find some strange readings
If hittest(whatever condition) = true { Health -= Health - 10; EnergyBar._xscale = Health; }
The second line should be Health -= 10;
If you're using different damages, it's a good idea to have that damage in a seperate value, making it a bit like this:
var damage1:Number = 10;
if(hitTest(mc1,mc2)){ Health -= damage1; }
Also, instead of changing the HP bar when the damage is dealt, perhaps an update function at the end of the code is a better idea... that way it only updates once, instead of possibly more than once per frame. (For instance, when a player is hit by three bullets at once.) This makes your code run a bit faster - it only has to execute the _xscale once, instead of three times!
And just so you know, Midmenj, there are probably better and more efficient ways of doing it. I am not a flash programmer...I know programming from a more generic view...thus, you most probably will be able to optimize the code I've shown you in more ways. Try to find things like PixelSmash did and work them out
And indeed... what you could do is get all of your code working, quick and dirty, and then optimize it so that it doesn't take as much computing. The less lines of script flash has to read, the faster it'll run!