A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: If score is above..?

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    7

    Question If score is above..?

    Hi, really annoying little problem I have going in Flash at the moment, I'm sure it's simple to a lot of you, but I'm rather slow with AS2.

    I have a dynamic text field with the var 'score' (no instance name). I'm trying to make it so when you have so much score, say 300, that when you press a button it will command a movieclip to play(); itself, and score will also be deducted.

    I have this code so far:

    on (release) {
    if(_root.score==300){
    _root.score = _root.score -300
    _root.movieclip3.play();
    }
    }

    .. Which does what I want, but it only works if the score is exactly 300, and this isn't what I want, so long as score is above 300 they should be able to press the button and command this movieclip (think of it like money).

    Please get back to me if you have a solution, and try to keep it really simple, I can't add much more baggage to this code, really, and I'm not that experienced with it.
    Thanks~

  2. #2
    Senior Member
    Join Date
    Nov 2001
    Posts
    1,145
    It's the conditional statement (programming speak for if something is true or false)

    _root.score == 300

    == means equals. Change that to >= which means "greater than or equal to."

    _root.score >= 300

    Code:
    on (release) {
    if(_root.score>=300){
    _root.score = _root.score -300
    _root.movieclip3.play();
    }
    }
    You can learn the code to control animations pretty easily.

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    7
    Ah, thank you! So simple.. Proves I'm slow. This is literally the first time I've needed help and not seen the answer anywhere else, too.
    I'm going to mention you in the credits of this game just for that bit of code, it's saved me hours of grief looking for the solution!

    Thank you for taking the time.

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