The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 2 of 2

Thread: AS3 health bar

  1. #1

    AS3 health bar

    Ive seen a lot of tutorials but none are really what im looking for. I have a square right now which is saved as troop1_mc. Inside that MC i have a green bar called healthBar_mc.

    Pretty much how can I get healthBar_mc to decrease health whether its scaleX or alpha.x or whatever. Ill Attach/copy the applicable code in. It would really help. Im still new to AS3.


    play_btn.addEventListener(MouseEvent.CLICK, begin);
    var infantry:Number = 2; // the speed at which object moves
    var infantryHealth:Number = 100;
    var healthBar = troop1_mc.healthBar_mc;

    function begin (yourEvent:Event):void {
    var castleDamage:Number = Math.random() *10;
    var castleDamageRounded= Math.round(castleDamage);

    troop1_mc.x += infantry;
    troop1_mc.addEventListener(Event.ENTER_FRAME, begin)

    if (troop1_mc.x >= 300){
    troop1_mc.removeEventListener(Event.ENTER_FRAME, begin)

    //Start Damage
    function causeDamage() {
    infantryHealth -= castleDamageRounded;

    if (infantryHealth >= -10){

    troop1_mc.removeEventListener(Event.ENTER_FRAME, begin)


    play_btn.removeEventListener(MouseEvent.CLICK, begin)
    } //Closes function begin

  2. #2
    make sure healthBar_mc registration point is on the left. Also fixed the function on how it probably should be.
    function causeDamage() {
       infantryHealth -= castleDamageRounded;
       if (infantryHealth <= 0){
          troop1_mc.removeEventListener(Event.ENTER_FRAME, begin)
    it's not about following tutorials, they're for you to understand as3 programming so you can do it yourself.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012