View Full Version : Flash Calculator
HeadlessMonster
02-06-2009, 05:04 PM
Can anyone point me to a nice tutorial or a template for a simple calculator? I never made one and the whole concept is a big "?" for me.
Just something with basics: addition/subtraction/division/multiplication.
Many thanks!
-HM :confused:
Kimchee
02-07-2009, 03:06 AM
Do you want graphing or just simple add, subtract, multiply, divide?
kkbbcute
02-08-2009, 07:48 AM
What type of calculator do you want? Actually flash already has things like sin cos and tan built in, so making a calculator which can do trigo is no harder than doing one which can do just + - * /.
Read up on how to manipulate multiple variables and how to use input text fields if you want to create a calculator by yourself. A knowledge of the arithmetic operators in Flash would be useful as well.
Good luck with your calculator!
HeadlessMonster
02-09-2009, 04:40 PM
Cool, so I do have the basic calculations, but in order to calculate the input text fields, I have to have a "calculate" button with an on release command.
I there a way to not have a "calculate" button to give the total - having the total automatically appear in the "total" dynamic text field?
Also, the numbers I am putting in and totaling are percentages. How can I tell the input and dynamic text fields they are percentages - rounding off to the nearest 10th?
Many thanks for your input and dynamic help! :D
-HM
HeadlessMonster
02-09-2009, 05:39 PM
Okay, I figured my needs out...exept one thing...
How can I have the "Total" dynamic text (which is a percentage) round to the nearest 100th? :confused:
-HM
grilldor
02-09-2009, 05:55 PM
Each Number instance have a method called "toFixed" example:
var n:Number = Math.PI;
trace(n.toFixed(2)); // 3.14
Edit :
the previous edits where because I was debating wether Number could be an "instance". Turns out that :
trace(n is Object); // true
HeadlessMonster
02-09-2009, 06:15 PM
Hmmm, okay, would I put this in the frame with my other code?
Where in here?
total_a = Number(firstnumber)-Number(secondnumber);
total_b = Number(total_a)/Number(thirdnumber)*100+"%";
Thanks!
grilldor
02-09-2009, 06:22 PM
are total_a and b strings you pass to a textbox? Its quite confusing because you are tossing numbers and strings all around with casts.
Without modifying your code too much you could add
total_a = Number(firstnumber)-Number(secondnumber);
total_b = (Number(total_a)/Number(thirdnumber)*100).toFixed(2)+"%";
HeadlessMonster
02-09-2009, 06:32 PM
Yes, they pass to a text box (dynamic).
But that bit of code you provided didn't work. I attached the FLA...
Thanks again for helping me out with this. I'm starting to get a grasp on math in AS.
grilldor
02-09-2009, 10:39 PM
Hey there, did a quick look and saw that you were using AS2. toFixed is available in AS3.
I really have poor knowledge of AS2 as I've never used it for anything of good quality. But I dont think there is a way other than using some hack like multiplying by 100, using Math.round, then dividing by 100.
Best thing to do if you ask me is to update your project to use AS3, its so much more powerfull anyways.
And you should probably add some kind of Calculate button istead of having the timeline loop like you do.
Hope this helps
orange gold
02-10-2009, 04:32 AM
yes.... in as2 you will want to use the Math.round function... they have it in the documentations or you can just google a tutorial for it if you want ;)
HeadlessMonster
02-10-2009, 03:20 PM
Hmmm, how would I add it to this AS2?
total_a = Number(firstnumber)-Number(secondnumber);
total_b = Number(total_a)/Number(thirdnumber)*100+"%";
I'm almost there! Thanks for all your insight!
-HM
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.