Go Back   CodingForums.com > :: Client side development > Flash & ActionScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-12-2012, 04:48 PM   PM User | #1
Triple
New to the CF scene

 
Join Date: Jul 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Triple is an unknown quantity at this point
Health bar! (AS 3)

ACTIONSCRIPT 3
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)
{
gotoAndStop("1")
}

if(health == 1)
{
gotoAndStop("2")
}

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?
Triple is offline   Reply With Quote
Old 09-09-2012, 07:33 PM   PM User | #2
djpaul1963
New Coder

 
Join Date: Apr 2012
Location: Athens GR
Posts: 58
Thanks: 0
Thanked 6 Times in 6 Posts
djpaul1963 is an unknown quantity at this point
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.
djpaul1963 is offline   Reply With Quote
Reply

Bookmarks

Tags
actionscript 3, coding, health, health bar, percentage

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:25 PM.


Advertisement
Log in to turn off these ads.