View Full Version : Adding textbox values together

11-14-2009, 04:51 PM
Hello all, I am kind of a newcomer to Flash so this might seem like a silly problem.

There are 5 "price" textboxes on a particular frame. On a separate frame someone chooses an item and it populates those textboxes. What I want to do is be able to add together all of the "price" textboxes to populate the "total" textbox. I have tried parsing each textbox as an integer and then making a function to find the total and populate the "total" textbox but this just isn't working. It still has the value of 0 when I export. If I try parsing as a number it gives me a NaN value.

Any Suggestions?

11-14-2009, 08:25 PM
it would be better if you upload source file

11-14-2009, 08:36 PM
If the prices are decimals, I don't think you can convert them to integers, which are whole numbers, eg 1, 12, 36, etc. To convert decimal strings, I think you need to convert them to Numbers.

11-14-2009, 09:04 PM
Have you tried casting the values?

var totalValue:Number;
totalValue= Number(myTextBox1.text)
totalValue+= Number(myTextBox2.text)
totalValue+= Number(myTextBox3.text)
etc, etc

11-14-2009, 10:47 PM
or you could extent the textbox class and add a proprty like numText that returns te text cast as a number

11-15-2009, 09:41 AM
You need to use parseInt or parseFloat, and you need to make sure that it is the plaintext that you are working with and not the htmlized version.