A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Adding 1 to a NUMBER

  1. #1
    Flasher
    Join Date
    Jun 2005
    Posts
    1,365

    Adding 1 to a NUMBER

    Hi. I want to be able to add/subtract 1 to a number that is in a dynamic text box, when the user presses the up or down arrows (up to add down to subtract). I know how to control the up and down arrows, my problem is adding 1. I can't seem to mathematically add 1... I can make it so that when the user clicks the up arrow, it adds a 1 to whatever was in it before, so basically, if the contents was 02 before, it would turn into 021... But I want it to go from 02 to 03, or 02 to 01! HOW CAN I DO THIS?!?!
    Any help is GREATLY appreciated!!

    Thanks,
    Sportzguy933

  2. #2
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    they all have proceeding zeros?
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  3. #3
    Ryan Thomson EvolveDesigns's Avatar
    Join Date
    Oct 2001
    Location
    British Columbia
    Posts
    3,338
    if the number in the text box is a variable (like textField == 1) you would just put textField++ on your up button and textField-- on your down button. To include a 0 before changes things a bit, you would have to put something like:

    "0" + textField++ which would include a 0 before your number which would work up until you hit a 3 digit number cause then it would be som ething like 0100 for 100 so you would need an if statement to remove the 0 if the number is more than 99.. Im sure I've provided too much info so feel free to ask me what the hell im talking about lol

    good luck!
    Evolve Designs Interactive Media
    the natural selection

  4. #4
    Flasher
    Join Date
    Jun 2005
    Posts
    1,365
    Hey. I understand exactly what you're saying, the problem is, it's not working. I'd actually rather not have the "0" in front, so that's not a problem. The probem is that I've done what you suggested, and it doesn't work! The code I have now is:

    on (keyPress "<Up>") {
    textBox++
    }

    And it doesn't add one! I just get "NaN", or "Undefined".

  5. #5
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    textBox="0"+(Number(textBox)+1);

    if you don't want the String "0" just keep the second part:
    Number(textBox)+1;

    gparis

  6. #6
    Flasher
    Join Date
    Jun 2005
    Posts
    1,365
    Thanks so much for the help! It worked!

    ~Sportzguy933

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