A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Ridiculous, nonsensical problem!!!!

  1. #1
    Senior Member
    Join Date
    Oct 2000
    Posts
    124
    OK, this is gonna sound ridiculous. and yet 2 experienced programmers cant figure it out.
    there are 2 input variables on the stage, 1 called IN1, the other called IN2, and a dynamic text field variable called output. all variables are set to accept only numbers. now here's where it gets tricky: on the button, I have attached this script:

    on (release) {
    output=IN1+IN2;
    }

    what keeps happening is that instead of adding the 2 numbers together, it is putting them next to each other, like a string. EG if you put in 5 for each variable instead of it adding up to 10, it displays 55. If i change the + sign to a - sign, it does the subtraction properly. WHAT THE HELL IS HAPPENING HERE? you may not believe me, but try it yourself.
    bill

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Posts
    148
    I think it is because when taext is displayed in a text field it is converted to a string, so when you add the two variables together it is adding to strings together.

    To add the two numbers together do this:

    on (release) {
    output=number(IN1)+number(IN2);
    }




  3. #3
    Senior Member
    Join Date
    Aug 2000
    Posts
    148
    the reason why it works when you substact them is because it is imposssibe to subtract a string from another so Flash automatically converts both strings into numbers

  4. #4
    Senior Member
    Join Date
    Oct 2000
    Posts
    124
    that worked! Its strange though because I made an entire stock calculator without ever coming across this problem before. do you know if it's supposed to do that?
    thanks
    bill

  5. #5
    Senior Member
    Join Date
    Aug 2000
    Posts
    148
    did you build your calculator in flash 4?

  6. #6
    Senior Member
    Join Date
    Oct 2000
    Posts
    124
    no, flash 5- and i even have scripts like this

    on (press, keyPress "<Enter>") {
    if ((IN2>3) and (IN2<5)) {
    TOTAL = (IN3-130)*IN1;
    VESTED = TOTAL*.75;
    MESSAGE = (T1+T2+T3)+" of your "+IN1+" options will be vested as of 12/29/04. Here's the projected value of your vested and unvested award.";
    UNVESTED = TOTAL-VESTED;
    }
    }

  7. #7
    Senior Member
    Join Date
    Aug 2000
    Posts
    148
    I think the things you encounterd only applied because the user input the values through text fields.

    It's only when you try to add to values that the user has input that it will add them together as strings. If you try any other type of data manipulation then the two strings will be converted into numbers.

    It's just because the command to add two strings together is the same as the comand to add to numbers together. ie .'+'.

    Can be a bit confusing at times though!

  8. #8
    Senior Member
    Join Date
    Oct 2000
    Posts
    124
    i'll say- thanks for your help, tho!
    bill

  9. #9
    Senior Member
    Join Date
    Jun 2001
    Location
    Virginia, USA
    Posts
    437
    Guess now you are a little more experienced programmer

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