# Need help with code to toggle button activity

**URL:** <https://forum.kirupa.com/t/need-help-with-code-to-toggle-button-activity/288289>\
**Category:** Uncategorized\
**Created:** [May 13, 2009, 6:56pm UTC](https://forum.kirupa.com/t/need-help-with-code-to-toggle-button-activity/288289 "2009-05-13T18:56:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![webguync](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/webguync/32/2434_2.png) [@webguync](https://forum.kirupa.com/u/webguync)\
**Post date:** [May 13, 2009, 6:56pm UTC](https://forum.kirupa.com/t/need-help-with-code-to-toggle-button-activity/288289/1 "2009-05-13T18:56:13Z")

</div>

Hi,

I have a set of 5 button that change their opacity when clicked to a lower opacity. What I need to add is the ability to “toggle” the button to go back and forth from 100% opacity to 20% or whatever and then back to 100%. I would also like to add the ability to fade the opacity instead of it changing all at once. Her is the code as I have it so far.

```auto

ClickMe.addEventListener(MouseEvent.CLICK,f);
ClickMe.buttonMode = true;
 function f(e:Event){

for(var i:uint=1;i<=5;i++){

this["B"+i].alpha = .5; 

}

}

```
