How to add a health bar to Flash

By sora120592

How to add a health bar to Flash How to add a health bar to Flash

Rate: (3 Ratings)

i presume you have read my former article about movie clip control, so this is an update to that file. i will show how to make an area with decreases health

Instructions

Difficulty: Moderate

Things You’ll Need:

  • to have read my last article.
  • Adobe flash CS3.
  • have a save game from this article: http://www.ehow.com/how_2183368_control-movie-clip-flash.html

Step1
Open your .Fla file from http://www.ehow.com/how_2183368_control-movie-clip-flash.html.
Step2
make an area you would like
to be the spot that gives
damage.
Step3
then make it a movie clip.
and call it what ever you'd
like. I've called min "collision area"
Step4
now go into the action script of your
new made movie clip.
Step5
now type in:
onClipEvent (load) {
damage = random(9)+1;
}
onClipEvent (enterFrame) {
if (this.hitTest(_root.player_mc)) {
_root.playerHp -= damage;
}
if (_root.playerHp<1) {
_root.playerHp = 0;
}
}
explanation;
playerHp is going to be the dynamic text box with the health.
player_mc is the name of our player in this case object.
we will be making a variable called damage because it is easier to change.
Step6
now we will make a dynamic text box
and give it the variable name "playerHp".
as you can see on the pic. there is
to types of boxes in the text box
properties window. the one called "instance name"
refers to the graphic part of the text box,
but the one called "var" refers to the text
inside of it.
Step7
now go to the main timeline' s
first frame and add:
playerHp = 100;
Step8
if you want to you can try to make a movie clip with a square with the scales x=200 and y=15, now ad to the script of this movie clip: onClipEvent (enterFrame){
this._xscale = _root.playerHp;
}
make sure it is placed like on the picture in compared to the
little "+".

Tips & Warnings

  • remember to play with the hitTest effect becasue it it one of the most important actions in actionscripting.
  • keep in mind that capital letters make a difference in Actionscripting.

Post a Comment

POST A COMMENT

Request a New How-To Article

Looking for more How To information? Chances are there’s an eHow member who knows how to do what you’re looking to do. Submit an article request now!

eHow Article: How to add a health bar to Flash

eHow Member: sora120592

sora120592

Enthusiast Enthusiast | 490 Points

Category: Computers

Articles: See my other articles

Related Ads