-
Designer, Programmer, Musician
[RESOLVED] Variable addition from input textbox
Hello guys,
I've tried a lot of things and i don't manage to do this. I'm have this soda machine, that you have to enter some numbers like cents to buy soda (i think fruitbeard or Nig13 helped with that once, not sure).
I have 3 textboxes, an input TB (there you enter your money), and 2 dynamic TB, one for monitoring the addition and one to show the money that rests in your wallet.
The first dynamic TB has $2.50 (buy i'm not using decimals, it only says 250)
The thing is, when you type let's say 10 on the input TB, the dynamic TB increase that number. myDynamicTB-=myTextBox.text. That works great. The myDynamicTB shows 240, the result of substracting 10 to 250.
But now i need to add the myTextBox entered value to be shown in the monitoring textbox with variable name myMonitor. I tried myMonitor += myTextBox.text that should work, but it doesn't. Instead of additing 10+10 =20, it shows this on the myMonitor textbox 1010. I tried myMonitor = myTextBox.text+myTextBox.text; i tried triggering the myText value to another numeric variable, but everything i try, instead of showing 20, that is the addition of 10+10 when you type 10 and then type 10 again, it shows 1010.
I know it's easy to do this but i'm new substracting and additing variables. Thanks in advance!
Last edited by angelhdz; 11-28-2012 at 05:51 PM.
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
Maybe try this...
Code:
myMonitor += parseInt(myTextBox.text)
or this...
Code:
myMonitor = parseInt(myTextBox.text)+parseInt(myTextBox.text);
-
.
Hi,
will also do the trick when using decimals
-
Designer, Programmer, Musician
Thanks both of you.
Precisely, yesterday i reed about the parseInt, but i didn't try it. Definitely that did the job. Now i know that the parseInt converts the numbers from a textbox and traduces it to numbers, so it can be added, something like that. I will try the parseFloat to use the decimals later, Thanks!
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
Designer, Programmer, Musician
Here is the work in progress. Thanks. http://sofistica2.zzl.org/soda.swf
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
Designer, Programmer, Musician
Fruitbeard i think you can help me with this. I'm having problems with my additions and substraction.
PHP Code:
var cantidad=250; //amout of money in the wallet
var saco=0; //money deposited on the soda machine
if(money.text!=""){ //if the input textbox is NOT empty, then do the script below
if(pressed==false){
pressed=true;
if(cantidad<50){ //if the amount of money left in the wallet is below 50 cents
//do nothing
}
//if not, if the value shown in the input textbox (money.text) and in the monitor textbox (saco) is lower than 50
else if(saco<50 && money.text<50){
//then show in the monitor textbox (saco) the value typed in the input textbox (money.text)
saco += parseFloat(money.text)
//increase or substract the value shown on the monitor textbox (saco), in other words, if you typed 50 on the input textbox, it will substract 50 of the cantidad amount.
cantidad -=saco;
//empty the input textbox
money.text=""
}
//if the monitor textbox and the input textbox is higher than 50
if(saco>50 && money.text>50){
//show 50 , the soda machine only supports .50 cents at once
saco=50;
}
trace("Pressed");
trace("Unpressed");
}
}
It works if i type 50 , or I deposit 50 from 10 to 10 (10+10+10+10+10) but if i type 10, then 60, it shows 60, and the machine only supports 50 cents, so it will substract 60 to the money in the wallet.
It's like a buying system, you have $2.50 in the wallet, and the soda cost $.50 cents, but i want the people enter any amount of money on the input textbox, but the monitor textbox only will retain 50 (.50 cents to buy the soda) and the rest will be stay on the wallet. Then when you click on the soda button, everything will reset to 0 but the cantidad variable that is the amount of money left in the wallet. Thanks
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
.
post the fla so i don't have to make up all these text boxes and things
-
Designer, Programmer, Musician
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
Designer, Programmer, Musician
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
.
i type in a number and nothing happens ??? i press the little button and ??
-
Designer, Programmer, Musician
Oh sorry, you have to press ENTER on the keyboard to deposit the money, when the saco variable has 50, then you can take out a coca cola from the machine.
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
.
Hi,
That was an awfully messy Fla Angel!!
I have made something for you to play around with, its not finished totally, but the ingredients are there.
Slightly different to your original, you ALWAYS use the Enter key, except for choosing and taking your drink.
-
Designer, Programmer, Musician
Hehe i know it's messy, because this is a very old project, i think it's my first project in flash.
However, it was working right before the money depositing thing. Before that, you only click on a soda and pick it up, and the soda sold out when reaching 0. Then i decided rescuing this project and take it to a next level, and I then implemented the money depositing system, but I didn't know how to do it very well. Yours is looking good. Only rests limit the "saco" variable or whatever you renamed it, to $.50 cents, that is the cost of the sodas. When reaching 50, you can not enter any other value until picking up the soda, then it resets to 0. That's the idea. And when the "cantidad" variable reaches 0 (the money in the wallet) then you can not buy any other soda.
Thanks for the help
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|