For what you are trying to do an array is moreso a complication than a solution, you've already divided that into two arrays anyways probably due to that imposition... and having two buttons to do it is unnecessary, but you might already be realizing that since you only have code for one of them anyways.
All you need is one button that toggles the current visible properties to their opposites.
var array:Array = [myMovieclip1, myMovieclip2,myMovieclip3, myMovieclip4];
myMovieClip1.visible = myMovieclip2.visible = false; // or the other two... whichever start out as invisible
btn.addEventListener(MouseEvent.CLICK, _acComp);
function _acComp(e:MouseEvent) : void {
for each(var item:MovieClip in array) {
item.visible = !item.visible;
}
}
lf you need to have two buttons doing the opposite as you say then clicking either button has to end up affecting all buttons, not just one of the arrays as you did. If each button has to do as you say then you should not be using the ! operator since that can switch to the opposite of what you intend, so you need to assign the specific state desired.
var wcArray:Array = [myMovieclip1, myMovieclip2];
var acArray:Array = [myMovieclip3, myMovieclip4];
acComp_btn.addEventListener(MouseEvent.CLICK, _acComp);
function _acComp(e:MouseEvent) : void {
for each(var item:MovieClip in acArray) {
item.visible = false;
}
for each(var item2:MovieClip in wcArray) {
item2.visible = true;
}
}
wcComp_btn.addEventListener(MouseEvent.CLICK, _wcComp);
function _wcComp(e:MouseEvent) : void {
for each(var item:MovieClip in wcArray) {
item.visible = = false;
}
for each(var item2:MovieClip in acArray) {
item2.visible = true;
}
}