View Full Version : adding variables
Candleshrine
October 24th, 2001, 08:48 PM
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?
Rob
October 24th, 2001, 09:51 PM
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.
eyezberg
October 25th, 2001, 05:43 AM
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
upuaut8
October 25th, 2001, 06:44 AM
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.
suprabeener
October 25th, 2001, 11:27 AM
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.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.