PDA

View Full Version : Calculating values of comboBox


webhound
11-01-2007, 04:09 PM
Hi hope someone can help me here!
I have a series of comboBox's each containing a data value ranging from 1-10 and other ranging from -10 to 10. When the user makes a selection from each comboBox it adds the value to a dynamic text field (through a listener).

The problem im having is, if the user starts in any order other than starting from the 1st comboBox (_root.cb8), it doesnt add the values correctly becuase i have this code:
mTotal = _root.cb8.selectedItem.data + _root.cb9.selectedItem.data + _root.cb10.selectedItem.data + _root.cb11.selectedItem.data + _root.cb12.selectedItem.data + _root.cb13.selectedItem.data + _root.cb14.selectedItem.data;

The question is, how do i get it to add the values correctly no matter what order the user makes a selection from?

Thanks in advance

Cota
11-01-2007, 08:14 PM
Add a listener to each combox box, an in the listener have mTotal += theCombobox.SelectedItem.data

webhound
11-02-2007, 10:50 AM
I have added a listener to each comboBox through a loop...

for (i=1; i<=7; i++){
_root['cb'+i].addEventListener("change", set1cbListener);
}

.........

Cota
11-02-2007, 02:49 PM
did that work for you? Whats the function look like?

webhound
11-02-2007, 05:44 PM
I figuered it out in the end..
The problem was that flash wasn't reading the values of the comboBoxes as numbers, so by adding: !isNaN to the begining of my loop i could be sure that Flash knows its a number ;)

for (var i:Number = 1; i<= 7; i++) {
if (!isNaN(Number(_root["cb"+i].selectedItem.data))) {
temp+=Number(_root["cb"+i].selectedItem.data);

}
}
pTotal = temp;