ActionScript - How to display a sum

  • DeadBolt
  • Novice
  • Novice
  • DeadBolt
  • Posts: 31

Post 3+ Months Ago

I am designing a Flash site where a customer can design a poker table and will show the cost for each item and at the end a total. I've got to the point where I need to know how to add all the text fields together and display a total.

So you have an idea of what I mean here is the swf: http://www.brochures.ca/test/customize_your_table.swf For example I just want tabletype + felt + Rail + etc. etc. = total. All of my text fields are DynamicText boxes and have variable names but I just can't figure out how to total them.

Thanks,
Dave
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1827
  • Loc: In the Great White North

Post 3+ Months Ago

you get the text field value with
Code: [ Select ]
var n1:Number = textfieldinstancename.text;
the :number should force the text to be a number instead of a string, but just to be sure when you add them together you want to use the number() command to force the string to a number. At that point flash can do "math" instead of tacking the strings onto the end of each other.
Code: [ Select ]
answertextfield.text = number(n1)+number(n2)+number(n3);
  • DeadBolt
  • Novice
  • Novice
  • DeadBolt
  • Posts: 31

Post 3+ Months Ago

Thanks for the reply/time graphixboy.

I'm getting some weird text in my price fields now. This is the code I have (Thanks again for that btw)

Code: [ Select ]
var n1:Number = Table_Type_price.text;
var n2:Number = Felt_price.text;
var n3:Number = Rail_price.text;

runningtotal.text = number(n1)+number(n2)+number(n3);
  1. var n1:Number = Table_Type_price.text;
  2. var n2:Number = Felt_price.text;
  3. var n3:Number = Rail_price.text;
  4. runningtotal.text = number(n1)+number(n2)+number(n3);


Now when I test the movie I get _level0_Felt_price for all my individual price fields and NaN in my runningtotal field.

Have any ideas what might be causing this?
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1827
  • Loc: In the Great White North

Post 3+ Months Ago

Hmm try this...
Code: [ Select ]
var n1 = number(Table_Type_price.text);
var n2 = number(Felt_price.text);
var n3 = number(Rail_price.text);

runningtotal.text = n1+n2+n3;
  1. var n1 = number(Table_Type_price.text);
  2. var n2 = number(Felt_price.text);
  3. var n3 = number(Rail_price.text);
  4. runningtotal.text = n1+n2+n3;


Also I would trace n1, n2, n3 individually to make sure each one of them really looks like a number.

If that doesn't work you may want to try parseInt(); instead of the number(); I'd check the Flash help on the usage, but I seem to remember it would pars content that is a mix of numbers/letters/etc

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 5 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.