Addition problem with script

OK… I’m still learning a bit about flash… but here’s my problem. I was just curious and messing about with variables… and decided to make an addition caculator… nothing fancy…

I first made 3 text boxes… 2 of them are input and one is dynamic… the first 2 have variable names of number1 and number2. The dynamic box variable is value… Then I made an invisible button that works when you hit the <enter> key. In that code, I basically just say value = number1 + number2 … but when I type say 20 in number 1 and 20 in number 2 box… I get 2020 for the value. I understand that this would work fine for strings, but I’m trying to add 2 numbers together. Now if I subtract or multiply… it works fine, but the addition isn’t. Any ideas why this is… or do I need to do this another way?

try this
value = Number(number1) + Number(number2);

This is because Falsh uses the same operator “+” for adding 2 numbers as well as joining to strings together. And doesn’t know what to chose and choses the operator for the type of values he recieve, because your text boxes are sending strings.

If an operator isn’t made for that type of data… as " or / is for strings… then Flash tries to interpret the type of data.
But this is only if it can’t do what you first told him… as multiplying a string with another string. And it can surely do a joint between 2 strings :).

:hugegrin: Worked like a charm… thanks man…

The Number(blah) will work great… There is also another way that will work. Multiply the variable by 1: ((var11) + (var21)) But the Number(var) is probably a better way to go.

-Bill