# RadioButton groups calculation!

**URL:** <https://forum.kirupa.com/t/radiobutton-groups-calculation/255237>\
**Category:** Uncategorized\
**Created:** [March 20, 2008, 11:15am UTC](https://forum.kirupa.com/t/radiobutton-groups-calculation/255237 "2008-03-20T11:15:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![eMnocean](https://avatars.discourse-cdn.com/v4/letter/e/e99b99/32.png) [@eMnocean](https://forum.kirupa.com/u/eMnocean)\
**Post date:** [March 20, 2008, 11:15am UTC](https://forum.kirupa.com/t/radiobutton-groups-calculation/255237/1 "2008-03-20T11:15:39Z")

</div>

Hello again,

I had posted a problem similar to this one a few days ago dealing with Checkbox calculations.

Well I got that one all figured out, but it turnes out I couldnt use that. What I need to figure out, is how to add up several groups of checkboxes. So again, bellow you’ll find the fla in the zip.

I’ve //included explanations (saying what it is doing) for every code section, and at the bottom I noted the section where I think the problem lives. Its only adding the first EventListener of each group.  
Sooo, Many hours later, I just cant seem to figure it out. Help!

here is the code and a snap shot, for who ever doesnt want to bother with opening the file… at first :block: . because who can resist 🙂

[URL=“[ImageShack - Best place for all of your image hosting and image sharing needs](http://img508.imageshack.us/img508/8239/test5gn6.jpg)”]

[URL=“[ImageShack - Best place for all of your image hosting and image sharing needs](http://img508.imageshack.us/my.php?image=test5gn6.jpg)”]

Thanx much, for who ever takes on the challenge.

> 

_//Here I will place the buttons in the A and B Group._  
A1.group = AGroup;  
A2.group = AGroup;  
B1.group = BGroup;  
B2.group = BGroup;

_//Here I declare the cost._  
var AOff:Number = 0;  
var BOff:Number = 0;  
var A1On:Number = 100;  
var A2On:Number = 200;  
var B1On:Number = 10;  
var B2On:Number = 20;

_//This is the innitial setting for the buttons. ( check that it maches w/ button setting)_  
var A:Number = A1On; _//RadioButtun $100 is on._  
var B:Number = B1On; _//RadioButtun $10 is on._  
Total.text = A + B; _//Total box is adding A+B (100+10)._

_//Here I create the formula for the A1 selection._  
A1Listener = new Object();  
A1Listener.click = function() {  
if (A1.selected) {  
A = A1On;  
}  
else {  
A = AOff;  
}  
Total.text = A + B;  
Trace ( A + B );  
};

_//Here I create the formula for the A2 selection._  
A2Listener = new Object();  
A2Listener.click = function() {  
if (A2.selected) {  
A = A2On;  
}  
else {  
A = AOff;  
}  
Total.text = A + B;  
};

_//Here I create the formula for the B1 selection._  
B1Listener = new Object();  
B1Listener.click = function() {  
if (B1.selected) {  
B = B1On;  
}  
else {  
B = BOff;  
}  
Total.text = A + B;  
Trace ( A + B );  
};

_//Here I create the formula for the B2 selection._  
B2Listener = new Object();  
B2Listener.click = function() {  
if (B2.selected) {  
B = B2On;  
}  
else {  
B = BOff;  
}  
Total.text = A + B;  
};

_//Here I listen for any selections._  
_ **//THIS IS WHERE I THINK THE PROBLEM LIVES.** _  
_ **//IT SEEMS TO ONLY LISTEN TO ONE OF EACH GROUP,** _  
_ **//IF YOU SWITCH THE NUMBERS, YOU’LL SEE.** _  
AGroup.addEventListener(“click”, A1Listener);  
AGroup.addEventListener(“click”, A2Listener);  
BGroup.addEventListener(“click”, B1Listener);  
BGroup.addEventListener(“click”, B2Listener);
