Adding variables

i have two input text boxes, speed1 and speed2, and one dynamic text box, textOutput. The user inputs a number into the two input text boxes. i have a button whose code goes something like

on (release){
textOutput = speed1+speed2;
}

however, if you put in 6 and 2, you would get 62 in textOutput. How can i make it so that it would equal 9?

Try using the Number() function:
on (release){
textOutput = Number(speed1)+Number(speed2);
}
This will work but you might get an error if the user enters anything besides a numeric.

6+2 can never equal 9 anyway, lol
if you use the + sign, Flash treats your input as strings, not numbers, and just (my favorite word) concatenates them: use eval maybe, or add, don´t remember exactly right now…gettin´old

6+2 can never equal 9 anyway, lol

roflmao…

I’m not laughing at you… I’m laughing with you. :slight_smile:

It’s a good question none the less.

when you assign your values to speed1 and and speed2 flash will decide whether it’s a string or a number (or an array, or…). you can force it to number by saying:

speed1 = new Number();
speed1 = 6;

or easier:

speed1 = Number(6);

once it’s a number you can refer to it just as speed1. it’ll stay a number until you explicitly change it or perform a string action on it.

but it should work without this stuff, i think maybe you quoted the numbers when you assigned them (speed1=“6”)? that will make flash treat them as strings and you’ll get concatenation rather than addition.

this is the danger of not having strongly cast data types.