I would like a better way to write this possibly using an array but I have been unsuccessful. See my code below. I need to add more details to post this but i can't think of more to say. I suppose I eventually need to have to set up a row of btnA show both B and C simultaneously as well. That would also be helpful.
I have a chart that either turns on a square or turns it off when clicked, for example btn3 toggles the visibility of checkMark3, works as written, but when I have 50 or 60 options of clicking the code is exhausting to write and becomes unruly
btnB1.addEventListener (MouseEvent.CLICK, showB1);
function showB1(event:MouseEvent) {
if (checkMarkB1.alpha == 1){
checkMarkB1.alpha = 0;} else {checkMarkB1.alpha = 1}
}
btnB2.addEventListener (MouseEvent.CLICK, showB2);
function showB2(event:MouseEvent) {
if (checkMarkB2.alpha == 1){
checkMarkB2.alpha = 0;} else {checkMarkB2.alpha = 1}
}
btnB3.addEventListener (MouseEvent.CLICK, showB3);
function showB3(event:MouseEvent) {
if (checkMarkB3.alpha == 1){
checkMarkB3.alpha = 0;} else {checkMarkB3.alpha = 1}
}
btnB4.addEventListener (MouseEvent.CLICK, showB4);
function showB4(event:MouseEvent) {
if (checkMarkB4.alpha == 1){
checkMarkB4.alpha = 0;} else {checkMarkB4.alpha = 1}
}
btnC1.addEventListener (MouseEvent.CLICK, showC1);
function showC1(event:MouseEvent) {
if (checkMarkC1.alpha == 1){
checkMarkC1.alpha = 0;} else {checkMarkC1.alpha = 1}
}
btnC2.addEventListener (MouseEvent.CLICK, showC2);
function showC2(event:MouseEvent) {
if (checkMarkC2.alpha == 1){
checkMarkC2.alpha = 0;} else {checkMarkC2.alpha = 1}
}
btnC3.addEventListener (MouseEvent.CLICK, showC3);
function showC3(event:MouseEvent) {
if (checkMarkC3.alpha == 1){
checkMarkC3.alpha = 0;} else {checkMarkC3.alpha = 1}
}
btnC4.addEventListener (MouseEvent.CLICK, showC4);
function showC4(event:MouseEvent) {
if (checkMarkC4.alpha == 1){
checkMarkC4.alpha = 0;} else {checkMarkC4.alpha = 1}
}
Add all your buttons to an array, and all your checkMarks to another array. Make sure that the order of the items in the array means that the position of each button in the buttons array corresponds with the position of its associated checkMark in the checkMarks array.
This should mean you can just add as many buttons and checkMarks as you like to the array, as long as you add them in the right order and always have a checkMark for every button.