Actionscript 2 question

Discussion in 'Programming' started by factchecker, Aug 26, 2006.

  1. #1
    I have a problem which I had no idea would be a problem and I can't find the solution anywhere:

    I have a form asking for the user to input 2 separate numbers
    Each number is assigned to a different variable.

    When I click the button to add the two numbers
    1 + 1 = 11 7+7+77

    When I do something like:
    var a:Number = 2
    var b:Numer = 4
    I can get a + b to = 6

    But when the numbers are coming from a form I would get 24

    This is driving me crazy.....

    How do I make 1 + 1 = 2

    Thank You

    I will addd rep points for any good answer
     
    factchecker, Aug 26, 2006 IP
  2. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #2
    seems like your variables are trying to concatenate the variables as strings vs. integer. (Flash uses + for string merging and the arithmetic functions as well). Do a Cast function to force the variable to be a number instead of a string :)

    pass in varNameA and varNameB variables.
    var a:Number;
    a = int(varNameA);
    var b:Numer;
    b = int(varNameB);
     
    ccoonen, Aug 26, 2006 IP
    factchecker likes this.
  3. factchecker

    factchecker Peon

    Messages:
    845
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thank you rep given...
     
    factchecker, Aug 26, 2006 IP
  4. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #4
    Rep Given?
     
    ccoonen, Aug 26, 2006 IP