PDA

View Full Version : checking buttons


bluegel
06-19-2003, 02:30 PM
hi

Ive got 15 buttons in a scene and want to have a way to check whether there have been at least one button selected and no more than 8 buttons selected. Is there a way of doing this?

thanx

catbert303
06-19-2003, 03:28 PM
Hi,

can the buttons be selected and then deselected again?

If so you could do something like this,


totalSelected = 0;
myButton.onPress = function() { // action in the same timeline as the button, where the button instance name is myButton
this.count++;
if (this.count % 2) { // count is an odd number, the button has been selected
totalSelected++; // add 1 to the count of selected buttons
} else { // count is an even number
totalSelected--; // the button was deseleted, reduce the count of selected buttons
}
};


you can add the same event for each button in the movie. then at the end you can check the value of totalSelected to see how many buttons are selected.

If the buttons can't be toggled on and off, you can just have each button do something like this,


myButton.onPress = function() {
if (!this.clicked) {
totalSelected++;
this.clicked = true; // stop the button being clicked on again
}
};


Hope this helps :)

bluegel
06-20-2003, 08:06 AM
hey

havent tried it yet, but it looks like it might be useful.

thanx, Ill let you know if it works