Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8220083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:23:52+00:00 2026-06-07T13:23:52+00:00

I am totally new at this whole programming thing, and I really need help.

  • 0

I am totally new at this whole programming thing, and I really need help. So basically, I’m trying to make a healthbar that will increase or decrease depending on what button is clicked. I made a healthbar movieclip with 101 frames (I included zero) and put this in the actionscript layer of the movieclip:

var health:Number = 0;

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

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

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

and on and on like so. Basically, on the stage itself, I have a button called fortyfiveup_btn that is commanded to do this:

var health:Number = 0;

fortyfiveup_btn.addEventListener(MouseEvent.CLICK, fortyfiveupClick);
function fortyfiveupClick(event:MouseEvent):void{
    health = health+45
}

I quickly realized that both health variables, the one for the button and the one for the healthbar will not interact. How can I make it so if the button is clicked, the health goes to the relevant frame or percentage?

Thanks for any answers, and I appreciate all the help I can get 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T13:23:56+00:00Added an answer on June 7, 2026 at 1:23 pm

    If the answer == yes to my comment you should do this:

    You need to give the movieclip an instancename (perhaps lifebar) and from stage you can access the health inside the “lifebar” with lifebar.health.

    So you need this inside your stage:

    //You can delete the var health:Number = 0;
    fortyfiveup_btn.addEventListener(MouseEvent.CLICK, fortyfiveupClick);
    function fortyfiveupClick(event:MouseEvent):void{
        //You can write this, too: lifebar.health += 45;
        lifebar.health = lifebar.health+45;
    }
    

    You can even optimize your lifebar script, don’t use 101 times the if(health == x) you can use this, too:

    gotoAndStop(health + 1);
    

    (I think this is inside an ENTER_FRAME event?)

    EDIT:

    Some error countermeasures:

    //Don't let health decrease below 0
    if(health < 0) health = 0;
    //And don't above 100
    else if(health > 100) health = 100;
    gotoAndStop(health + 1);
    

    Use int instead of Number when you don’t use decimal numbers and uint when you don’t use negative integers (this bugs when the number can drop under 0, so for your health we take int):

    health:int = 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm totally new to this WCF Services thing so any guidelines would be greatly
Totally new to programming so kindly excuse the silly question. I have this URL
Please bear in mind that I'm totally new to Rails when answering this.My question
This question shows the usage of **var = new Object(); and that's something totally
im totally new when it comes to trying to make HTML code. I was
Im totally new to regex. I need your help. What is the regex function
I'm totally new in C, and I'm trying to do a little application that
I'm totally new to powershell, and I need some help to get started. What
I am totally new to Joomla. I am trying to help a friend whose
I am totally new in programming. For my first programm I tried to make

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.