View Full Version : Health bar! (AS 3)

07-12-2012, 05:48 PM
Hey, I'm having trouble with a health bar in my game. I'm a total beginner at Flash, and when I saw that, I mean I have almost no idea what I'm doing.

I started off by making a movie clip. Inside, I made a 101 frame (I included 0%) tween. Then I made a layer for actions in the movie clip, I wrote this in the actionscript:

var health:Number = 0;

if(health == 0)

if(health == 1)

and on...

Anyway, I quickly realized that the health variable will not work outside of the movie clip, like if I were to make a button and did the actionscript like:

var health:Number = 0;

fortyfiveup_btn.addEventListener(MouseEvent.CLICK, fortyfiveupClick);
function fortyfiveupClick(event:MouseEvent):void{
health = health-5

it would not take the health out from health bar. Can you please help me out in the simplest way possible?

09-09-2012, 08:33 PM
2 things here:
First, you give your health movie clip a name, let's say health_bar. Whenever you want to move the playhead of that movie clip you must targetting that name. (health_bar.gotoAndStop(frame_number)) or else you move your main movie playhead instead of the health_bar.
Second, you don't have to name each one of your keyframes for the gotoAndStop to work. You just enter the frame number. And that way you don't have to have 100 keyframes!
I hope I made it clear.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum