# Best active state buttons

**URL:** <https://forum.kirupa.com/t/best-active-state-buttons/281727>\
**Category:** flash\
**Created:** [February 12, 2009, 6:34pm UTC](https://forum.kirupa.com/t/best-active-state-buttons/281727 "2009-02-12T18:34:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![xPINKMERCEDESx](https://avatars.discourse-cdn.com/v4/letter/x/73ab20/32.png) [@xPINKMERCEDESx](https://forum.kirupa.com/u/xPINKMERCEDESx)\
**Post date:** [February 12, 2009, 6:34pm UTC](https://forum.kirupa.com/t/best-active-state-buttons/281727/1 "2009-02-12T18:34:02Z")

</div>

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:

> **[Real Estate Agency Website Template #22745](https://www.templatemonster.com/website-templates/22745.html)**
>
> 【Real Estate Agency Website template #22745】 - enjoy clean, professional and... ✅【Before You Buy】 - learn technical specifications, read reviews, ask a question.... ✅【Quality Control】 - this premium Website template has passed QC by professional......

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);  
}  
}  
}
