Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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?

  • #2
    New Coder djpaul1963's Avatar
    Join Date
    Apr 2012
    Location
    Athens GR
    Posts
    75
    Thanks
    0
    Thanked 8 Times in 8 Posts
    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.


  •  

    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
    •