Best active state buttons

I have the coveted code to have active states for buttons in actionscript 3.0 . However, there’s one problem.

First, let me explain the code.

there are an array of buttons and an array of button urls.

Now, when a user rolls over a button, the button plays the “open” frame inside the button. When the user rolls off the button, the button plays the “close” frame of the button. When a user presses the button, the button goes to the “dock” frame of the button. Here’s the problem : when a user clicks a button, all the other buttons go to their “close” frame when only the button that’s previously open when the user clicks a differen button should go to the “close” frame.

More emphatically, a function is needed to check to see if any buttons are in the open state (not a frame 1) when a user clicks a buttons. The way the code is now, when a user clicks a button, all the other buttons go to their “close” frame when only the button that was open should go to their “close” frame. Thus, if any button is not open when a user clicks any button, then, that button shouldn’t do anything.

Thus, the buttons should work like these buttons when you click:

here’s the code:

stop();

var buttons_array:Array=new Array(homes, cars, assets, bmw,benz,navi);
var buttons_urls :Array=new Array();
for (var i:int=0; i<buttons_array.length; i++)
{
buttons_array*.mouseChildren=false;
buttons_array*.buttonMode=true;
buttons_array*.id=i;
buttons_array*.addEventListener(MouseEvent.ROLL_OVER, onRollover);
buttons_array*.addEventListener(MouseEvent.ROLL_OUT, onRollout);
buttons_array*.addEventListener(MouseEvent.CLICK, buttonClicked);
}

function onRollover(e:MouseEvent):void
{
e.target.gotoAndPlay(“open”);
}

function onRollout(e:MouseEvent):void
{
e.target.gotoAndPlay(“close”);
}

function buttonClicked(e:MouseEvent):void
{
buttonSelected(e.target.id);
var url:URLRequest = new URLRequest(buttons_urls[e.target.id]);
navigateToURL(url, “_blank”);
}

function buttonSelected(id:int):void
{
for (var i:int=0; i<buttons_array.length; i++)
{
if (i==id)
{
buttons_array*.gotoAndStop(“dock”);
buttons_array*.buttonMode=false;
buttons_array*.removeEventListener(MouseEvent.ROLL_OVER, onRollover);
buttons_array*.removeEventListener(MouseEvent.ROLL_OUT, onRollout);
buttons_array*.removeEventListener(MouseEvent.CLICK, buttonClicked);
} else {
buttons_array*.gotoAndPlay(“close”);
buttons_array*.buttonMode=true;
buttons_array*.addEventListener(MouseEvent.ROLL_OVER, onRollover);
buttons_array*.addEventListener(MouseEvent.ROLL_OUT, onRollout);
buttons_array*.addEventListener(MouseEvent.CLICK, buttonClicked);
}
}
}