Join Login


Fotolia
 Small Checkbox related Calculator.
 by Rukey - Sep 04, 2010

Hello,

Putting this very plain and simply I'm trying to make a carbohyrdrate style calculator in Adobe Flash CS3 (Actionscript 2.0) for a friend. I'm not very good with actionscript as you will see but I could do with a helping hand if that's at all possible!

It's simple (In theory) 3 Checkboxes, an input (Pounds) textbox and an dynamic output field. As seen in the image below.

http://i174.photobucket.com/albums/w106/rukey1/flashcarbcalc.jpg

all I want to be able to do is if the user selects one of the Checkboxes for example "Gain Muscle" and the calculate would entail "Pounds entered x 2".
"Maintain" = "Pounds entered x 1.5"
"Loose" = "Pounds entered x 0.8"

But the thing I'm struggling with is how I can do an if/else statement so whatever the user selects as their checkbox it runs the code for.

http://i174.photobucket.com/albums/w106/rukey1/actionscript20.jpg

I've tried numerous different ways and I think I'm making it much more complicated than it is.

Thanks! Love all the video tutorials by the way!


Rukey
United Kingdom
Posts:12
Joined:Jan 06, 2010
 RE: Small Checkbox related Calculator.
 by RiverCityGraphix - Sep 06, 2010

Is it possible for me to give you the AS3 version. I have much more experience with AS3 than AS2. I can help you for AS2 but I do not know how fast you need it and it will take me a bit longer to find the correct conversions.


Be sure to subscribe on YouTube.

Do you take great photos? Consider selling them on Dreamstime.
RiverCityGraphix
United States
Posts:327
Joined:Nov 21, 2009
 RE: Small Checkbox related Calculator.
 by Rukey - Sep 06, 2010

By all means give me an AS3 version. It's better for me to AS3 anyway. As long as it's not trouble for yourself. Thanks very much for your help!


Rukey
United Kingdom
Posts:12
Joined:Jan 06, 2010
 RE: Small Checkbox related Calculator.
 by RiverCityGraphix - Sep 06, 2010

Ok, here is what I did for you. I set it up using radio buttons and a numeric stepped instead of checkboxes and a text input. The reason I changed it was becasue with a nummeric stepper there is no chance that a non-number value can be added which makes it easier for the AS. The checkboxes were ok except that more than one can be checked at a time. This is the reason that I used radio buttons (only one selected at a time.) I have the file if you want it later but for now, here is the ActionScript 3.0.

import fl.controls.RadioButtonGroup;
var group:RadioButtonGroup = new RadioButtonGroup("My Question");

rbtn1.group = group;
rbtn2.group = group;
rbtn3.group = group;

rbtn1.label = "Gain Muscle";
rbtn2.label = "Maintain";
rbtn3.label = "Lose";

rbtn1.selected = true;
numstep.value = 0;
numstep.maximum = 100;
resulttxt.text = "0";

rbtn1.addEventListener(MouseEvent.CLICK, poundschange);
rbtn2.addEventListener(MouseEvent.CLICK, poundschange);
rbtn3.addEventListener(MouseEvent.CLICK, poundschange);
numstep.addEventListener(Event.CHANGE, poundschange);

function poundschange (event:Event):void{
if(group.selection.label == "Gain Muscle"){
resulttxt.text = Math.round(numstep.value * 2) + "";
}
if(group.selection.label == "Maintain"){
resulttxt.text = Math.round(numstep.value * 1.5) + "";
}
if(group.selection.label == "Lose"){
resulttxt.text = Math.round(numstep.value * 0.8) + "";
}
}


The way this is set up is so that it will update the result if either a new radio button is clicked or the numeric stepper changes. I hope this helps.


Be sure to subscribe on YouTube.

Do you take great photos? Consider selling them on Dreamstime.
RiverCityGraphix
United States
Posts:327
Joined:Nov 21, 2009
 RE: Small Checkbox related Calculator.
 by Rukey - Sep 07, 2010

I had a go myself but didn't know if I should change the instance names of all the radio buttons or not, or if I should make new layers for radio buttons / input text area / number stepper. Is the actionscript meant to go behind a button? or just behind the whole process?

I had a go: http://www.megaupload.com/?d=CRTRAOPG (343Kb approx). I appreciate the help!


Rukey
United Kingdom
Posts:12
Joined:Jan 06, 2010
 RE: Small Checkbox related Calculator.
 by RiverCityGraphix - Sep 07, 2010

Would you rather me try and fix your file you send you mine. It doesn't really matter, but it may help you to see how I set everything up.

I put it here for download if you want: Rukey Calculator


Be sure to subscribe on YouTube.

Do you take great photos? Consider selling them on Dreamstime.
RiverCityGraphix
United States
Posts:327
Joined:Nov 21, 2009
 RE: Small Checkbox related Calculator.
 by Rukey - Sep 07, 2010

I tried to open it in CS3 and it complains about "Unexpected file format". Even though it's an .fla. Makes me wonder sometimes...


Rukey
United Kingdom
Posts:12
Joined:Jan 06, 2010
 RE: Small Checkbox related Calculator.
 by RiverCityGraphix - Sep 07, 2010

Oh, Im sorry. I am using Flash CS4 so when I save it the default is set to a CS4 file. I re-saved the file as a CS3 format so you should be good to go. It is the same download link a before.


Be sure to subscribe on YouTube.

Do you take great photos? Consider selling them on Dreamstime.
RiverCityGraphix
United States
Posts:327
Joined:Nov 21, 2009
 RE: Small Checkbox related Calculator.
 by RiverCityGraphix - Sep 08, 2010

Is that going to work for you? Were you able to open the new file?


Be sure to subscribe on YouTube.

Do you take great photos? Consider selling them on Dreamstime.
RiverCityGraphix
United States
Posts:327
Joined:Nov 21, 2009
 RE: Small Checkbox related Calculator.
 by Rukey - Sep 08, 2010

Yes thank you very much! Now I realise that I only needed one layer, change the instance names of the radio boxes! I might be making similar calculator's in a simple way to yours!

I really appreciate the help! I'll will keep you updated if you wish and I will make sure that me and a friend credit you and your website on ours.


Rukey
United Kingdom
Posts:12
Joined:Jan 06, 2010
 RE: Small Checkbox related Calculator.
 by RiverCityGraphix - Sep 08, 2010

Cool, Im glad it works. If you have any more questions feel free to post them, I'd be glad to help.


Be sure to subscribe on YouTube.

Do you take great photos? Consider selling them on Dreamstime.
RiverCityGraphix
United States
Posts:327
Joined:Nov 21, 2009
 RE: Small Checkbox related Calculator.
 by Rukey - Jul 27, 2011

It's been awhile since I visited this forum! I'm glad it's still around! :D I'm still using the calculator you edited for me awhile back. Although I've updated to Flash CS5 since the time of CS3. Now I realise that the calculator doesn't do as it is meant to.

http://bodybuildingdatabase.com/nutrition/carbohydrates-2/carb-calculator/

The code is exactly the same as it is above yet it seems to only allow certain values.


Rukey
United Kingdom
Posts:12
Joined:Jan 06, 2010
  
Home About Contact Forum Youtube Privacy Policy
Copyright © 2009-2011 RiverCityGraphix.All Rights Reserved.