A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: How do i check a value?

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    2

    Unhappy How do i check a value?

    Hi,
    this is my first post on flashkit so sorry if im a bit weak on my description, but anyway.

    I am trying to make a simple flash game, which involves a target which moves around, a cursor in the shape of a gun's scope, a healthbar of the target, so it will take multiple shots, and finally a "you win" screen.

    I have done the target, the cursor, the healthbar fine. the actionscript works, the healthbar decreases by the given amount etc.

    The only problem is, i cant get it to go to the next frame when the healthbar reaches zero.

    Im using Actionscript 2.0 and dont really want to change to 3.0 yet.
    This is what i have so far...

    The frame...
    Actionscript Code:
    stop();
    // The amount of health that the target has.
    health = 100

    This is the script on the healthbar. This works fine as it is.
    Actionscript Code:
    onClipEvent(enterFrame){
    healthwidth = (_root.health*3.2) // for a health bar of 320. the number is what you times 100 by to get the maximum width
    healthbar._width = healthwidth
    }
    This is the script on the Target. ( a button ).
    Actionscript Code:
    //This will remove 10 health on release.
    on (release) {
            _root.health--;
            _root.health--;
            _root.health--;
            _root.health--;
            _root.health--;
            _root.health--;
            _root.health--;
            _root.health--;
            _root.health--;
            _root.health--;
    }
    (note, is there a way i can get it to remove 10 without repeating that over and over? I tried _root.health - 10, --10 etc. and it wouldnt work.)

    Now, heres the problem. When the healthbar empties, nothing happens. how can i get it to proceed to frame 3 when the healthbar becomes empty? (so the health variable, on the frame is 0 or less.)

    I have tried...
    Actionscript Code:
    if(health=0){
    gotoAndPlay(3)
    But this just set the health value to 0 straight away
    };

    I have tried >= and <=, More than or equal, puts it to the "you win" screen.
    Less than or equal doesnt do anything when the health reaches 0.

    I dont know what to do

    The fla file is attached for those who want to have a look... (yes its an MX04 file, i made this at school. Thats one reason i dont want to learn AS3 yet.)
    Attached Files Attached Files

  2. #2
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    if(health=0){
    gotoAndPlay(3)
    }

    it needs to be == not = so

    if(health==0){
    gotoAndPlay(3)
    }


    NOTE
    == compares, = sets

  3. #3
    Junior Member
    Join Date
    Jul 2010
    Posts
    2

    Re:

    hmm... i tried this, but for some reason, it doesnt advance to frame 3.
    i have updated the script as you say, but it doesnt move on. check the new attachment...
    Attached Files Attached Files

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    _root.health-=10;

    will remove 10 from _root.health.

    For help on the othe issue i suggest you attach a copy of the fla in an older version of Flash, like CS3 or 4, since not everybody got CS5 yet (a lot of us are waiting for a more stable CS5)

    gparis

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center