all groups > flash actionscript > july 2007 >
You're in the

flash actionscript

group:

Simple Math


Simple Math steeleLtd
7/23/2007 8:25:46 PM
flash actionscript:
it's been a while since I have tinkered with flash. I am trying to do some very
simple math and have completely lost my senses.

Say I have 2 input text boxes... Value1 and Value2

I have a dynamic box call "RESULT" to display the result of : Value1+Value2

This is very simplified for what I need to accomplish,- but what is the
solution?

Thanks
Re: Simple Math kglad
7/23/2007 8:28:09 PM
Re: Simple Math steeleLtd
7/23/2007 8:39:03 PM
Thanks Keith, you have always been an incredible advisor on stuff like this..

I did set the variables at it looked like this..

Input box instances were named Value1 and Value2, the variables were v1 and
v2. Dynamic instance was named Result1 and variable was r1...


var Value1:Number = v1
var Value2:Number=v2
var Result1:Number=ra

ra=v1+v2


I know I need to get back in the groove, but I am really missing something
basic.
Re: Simple Math kglad
7/23/2007 8:48:01 PM
using variable typing won't convert a string to a number. use:



Re: Simple Math steeleLtd
7/23/2007 9:06:56 PM
I get a NaN error in the DYNAMIC text box...

Re: Simple Math kglad
7/23/2007 9:32:24 PM
if v1 and v2 are instance names, use v1.text and v2.text instead of v1 and v2
inside the Number() function. if v1 and v2 are variable names make sure
neither of your textfields have html enabled and they do not have auto kern
checked.
Re: Simple Math steeleLtd
7/24/2007 1:28:15 PM
Re: Simple Math kglad
7/24/2007 1:36:28 PM
you're welcome.

auto kern enables html in your textfield. so, the variable value of a
textfield that contains the number 5 actually looks something like:

<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Arial" SIZE="16"
COLOR="#00FF66" LETTERSPACING="0" KERNING="0">5</FONT></P></TEXTFORMAT>
Re: Simple Math steeleLtd
7/24/2007 2:24:20 PM
Re: Simple Math kglad
7/24/2007 2:25:50 PM
Re: Simple Math steeleLtd
7/24/2007 3:08:48 PM
So, the very last line needs to add up all of the math in the first ten
variables... following your example from before and applying that to the last
line, I get the dreaded NaN...

Wouldnt the formula work for simple addition of variables?

trdtotval1 = Number(trditem1)*Number(trdval1);
trdtotval2 = Number(trditem2)*Number(trdval2);
trdtotval3 = Number(trditem3)*Number(trdval3);
trdtotval4 = Number(trditem4)*Number(trdval4);
trdtotval5 = Number(trditem5)*Number(trdval5);
trdtotval6 = Number(trditem6)*Number(trdval6);
trdtotval7 = Number(trditem7)*Number(trdval7);
trdtotval8 = Number(trditem8)*Number(trdval8);
trdtotval9 = Number(trditem9)*Number(trdval9);
trdtotval10 = Number(trditem10)*Number(trdval10);
//
var trd1val:Number = trdtotval1;
var trd2val:Number = trdtotval2;
var trd3val:Number = trdtotval3;
var trd4val:Number = trdtotval4;
var trd5val:Number = trdtotval5;
var trd6val:Number = trdtotval6;
var trd7val:Number = trdtotval7;
var trd8val:Number = trdtotval8;
var trd9val:Number = trdtotval9;
var trd10val:Number = trdtotval10;
//
trdtotal00 =
Number(trd1val)+Number(trd2val)+Number(trd3val)+Number(trd4val)+Number(trd5val)+
Number(trd6val)+Number(trd7val)+Number(trd8val)+Number(trd9val)+Number(trd1val0)
;
Re: Simple Math kglad
7/24/2007 3:49:00 PM
Re: Simple Math Steele Imaging
7/24/2007 5:13:32 PM
Not that I am aware of... :)

I basically need the values of the variables: trdtotval* (in the first group)
to be added together for the sum of all the variables to be displayed.

basically, you have shown me that the variable trdtotval1 will eaqual trditem1
multiplied by trdval1 in this code:
trdtotval1 = Number(trditem1)*Number(trdval1);

To give you an idea of the application, say "trditem1" (which stands for
'Trade Item') is 50 concert tickets, and "trdval1" (which stands for 'Trade
Value') is equal to $10.00 (although i have yet to learn how to convert to a
currency format, we just call it 10) - Then the "trdtotval1" (which stands for
'trade total value') will equal 500 ($500.00)

Now, I have inputs for ten trade items and I need to get the total value for
each line/item. At the end of the application, I need to complete total of ALL
TEN line items.

So... it would look something like this:

1. 5 10 General Admission Tickets 50
2. 5 5 Parking Passes 25
(ten items like the above)

TOTAL: ------------------------------------------- 75

I need the total (75)

Does that make sense?
Re: Simple Math kglad
7/24/2007 10:01:14 PM
Re: Simple Math steeleLtd
7/25/2007 1:20:32 AM
See Keith... this is what happens when you give a 3 year old with mild learning disorders a PC with a fancy flash program.
Thanks,
Your lil' idiot buddy.
Dave

Re: Simple Math kglad
7/25/2007 2:16:13 AM
AddThis Social Bookmark Button