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 8639629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:03:56+00:00 2026-06-12T11:03:56+00:00

I have created a bar where it is full on frame 1, then empty

  • 0

I have created a bar where it is full on frame 1, then empty on frame 100, and I’ve made it into a shape tween. I want to create a code where when I press a certain button, it depletes the bar, so the frame goes from 1 until it reaches 100 as long as a certain button is held.

I was thinking of a way to do this, but it seems impossible.

var maxHP:int = 100;
var currentHP:int = maxHP;
var percentHP:Number = currentHP / maxHP;

I would like to have the percentHP var equal the bar, so as it gets to 50, it’ll reach frame 50, and so on.

Is this the correct way of going about this?

Thanks.


Here are the variables being used in the code I’m trying to fix below. Also, the game I’m creating has multiple characters, so the bar I’m referring to is within a couple of movieclips.

Basically, when the character double jumps, it is flying, and the bar depletes. Once the bars depletes to 0(Or when PercentHP is 0) then it should end the flying. Afterwards, I would like the bar to fill back up towards 100 overtime.

var percentHP = Number(Bar.CBar.CMana_bar.currentFrame) / Number(100);
var gravityConstant:Number = 1;   
var doubleJumpReady:Boolean = false;
var flyingJump:Boolean = false;
var upReleasedInAir:Boolean = false;

function loop(e:Event):void{
    //Flying
            if(upReleasedInAir == true){ // if the player releases the up arrow key
                upReleasedInAir = false; // set the variable to true
            }
            if(doubleJumpReady == false){
                doubleJumpReady = true;
            }
        } else { //if we are not touching the floor

            ySpeed += gravityConstant; //accelerate downwards

            //Flying
            if(upPressed == false && upReleasedInAir == false){
                upReleasedInAir = true;
                //trace("upReleasedInAir");
            }
            if(doubleJumpReady && upReleasedInAir){
                if(upPressed){ //and if the up arrow is pressed
                    flyingJump = true;
                    //trace("doubleJump!");
                    doubleJumpReady = false;
                    ySpeed = jumpConstant + 8; //set the y speed to the jump constant
                    gravityConstant = 0;
                    Bar.CBar.CMana_bar.play();
                    //trace(percentMP);
                }
                }
                if(Bar.CBar.CMana_bar.currentFrame == 100 && percentHP == 0){
            gravityConstant = 1;
            Bar.CBar.CMana_bar.stop();
            flyingJump = false;
            doubleJumpReady = false;
        }
  • 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-12T11:03:58+00:00Added an answer on June 12, 2026 at 11:03 am

    What you should do is attach a MOUSE_DOWN and MOUSE_UP event to your button. Type in stop(); in frame 1 of your bar and then use MOUSE_DOWN and MOUSE_UP to play or stop the animation in your bar. Something along the lines of:

    button.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    button.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
    function mouseDownHandler(e:Event):void{
    bar.play();
    } 
    function mouseUpHandler(e:Event):void{
    bar.stop();
    percentHP = Number(bar.currentFrame) / Number(100); //If you still need to know the percent
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

friends, i have created custom title bar using following titlebar.xml file with code <?xml
I have created a search bar for my website, the user may search a
I have created an tab bar application having 3 tab. When I am launching
I have created a Tab Bar Application, removed the default FirstView and SecondView and
I am new to this iphone development.I have created a tab bar application which
I have created a flexible navigation bar in my app that will show custom
I have created an application that creates bar graph based on inputs read from
I have created an activity which sends a number of notifications to status bar.
I am new to iphone development.I have created a UIBarButtonItem on the navigation bar.I
I have a horizontal menu bar created using ULs and LIs. The issue I

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.