# Adding variables

**URL:** <https://forum.kirupa.com/t/adding-variables/3536>\
**Category:** flash\
**Created:** [October 25, 2001, 12:48am UTC](https://forum.kirupa.com/t/adding-variables/3536 "2001-10-25T00:48:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 25, 2001, 12:48am UTC](https://forum.kirupa.com/t/adding-variables/3536/1 "2001-10-25T00:48:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 25, 2001, 1:51am UTC](https://forum.kirupa.com/t/adding-variables/3536/2 "2001-10-25T01:51:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 25, 2001, 9:43am UTC](https://forum.kirupa.com/t/adding-variables/3536/3 "2001-10-25T09:43:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 25, 2001, 10:44am UTC](https://forum.kirupa.com/t/adding-variables/3536/4 "2001-10-25T10:44:10Z")

</div>

> 6+2 can never equal 9 anyway, lol

roflmao…

I’m not laughing at you… I’m laughing with you. 🙂

It’s a good question none the less.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 25, 2001, 3:27pm UTC](https://forum.kirupa.com/t/adding-variables/3536/5 "2001-10-25T15:27:31Z")

</div>

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.
