PDA

View Full Version : Variables from Text Box


jptton
05-04-2001, 02:42 PM
I need to place two text boxes on stage and be able to input numbers and have them added upon pressing a button and the total output into a 3rd text box I think the action would be XXX=number(YYY)+number(ZZZ)having set these variables in text options I always get NaN for answer when clicking my button to do the calc I know this is simple problem but I just cant seem to see it. Thanks

[Edited by jptton on 05-04-2001 at 09:45 AM]

Marx
05-04-2001, 04:18 PM
Hi..
The following will add the values of two textfields then output the result to a third textfield:

1) Place two input and one dynamic textfields on your stage. Name them, box1, box2 and result.
2) Place abutton that will do the calculations on your stage, add the script:

on (release) {
result = Number (box1)+Number (box2);
}

Hope this helps.

jptton
05-04-2001, 04:56 PM
Thats what I have been doing still get NaN (not a number)
James

Marx
05-04-2001, 05:24 PM
Hi..
Thats definately the way to do it.
Textfields by default are strings thats why we use the Number function to let Flash know the values are numeric.

Place the textfields on your stage. Select your button symbol, now just 'copy & paste' the script directly into your actions panel. You'll be able to see how the code was entered.

Just to reiterate, using the number function is the best way to go.

Good luck.