# How to toggle simple buttons, call same function

**URL:** <https://forum.kirupa.com/t/how-to-toggle-simple-buttons-call-same-function/316497>\
**Category:** flash\
**Created:** [November 23, 2010, 3:43pm UTC](https://forum.kirupa.com/t/how-to-toggle-simple-buttons-call-same-function/316497 "2010-11-23T15:43:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![m2244](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@m2244](https://forum.kirupa.com/u/m2244)\
**Post date:** [November 23, 2010, 3:43pm UTC](https://forum.kirupa.com/t/how-to-toggle-simple-buttons-call-same-function/316497/1 "2010-11-23T15:43:59Z")

</div>

Hello,

I made 5 buttons on the stage. When these buttons are clicked I want to show AND hide items related to the buttons. Is there a way to “toggle” a simple button so that when it is cliked the first time it shows the object, clicked a second time it hides the object using the same function? In other words, is there a property of a simple button that changes state?

```auto

 
btnClss1.addEventListener(MouseEvent.CLICK, handleClass);
btnClss2.addEventListener(MouseEvent.CLICK, handleClass);
btnClss3.addEventListener(MouseEvent.CLICK, handleClass);
btnClss4.addEventListener(MouseEvent.CLICK, handleClass);
btnClss5.addEventListener(MouseEvent.CLICK, handleClass);

function handleClass(evt:MouseEvent):void
{
 if (1 == 1)
 {
  trace(evt.target.selected);
  allPresent ++;
  switch (evt.target.name)
  {
   case "btnClss1" :
    stage.addChild(addRegional);
    //btnClss1.x = 422;
    break;
   case "btnClss2" :
    stage.addChild(addSectional);
    //btnClss2.x = 422;
    break;
   case "btnClss3" :
    stage.addChild(addPrimary);
    //btnClss3.x = 422;
    break;
   case "btnClss4" :
    stage.addChild(addToll);
    //btnClss4.x = 422;
    break;
   case "btnClss5" :
    stage.addChild(addEnd);
    //btnClss5.x = 422;
    break;
  }
 }
 else if (1 == 0)
 {
  allPresent--;
  switch (evt.target.name)
  {
   case "btnClss1" :
    stage.removeChild(addRegional);
    //btnClss1.x = 61;
    break;
   case "btnClss2" :
    stage.removeChild(addSectional);
    //btnClss2.x = 61;
    break;
   case "btnClss3" :
    stage.removeChild(addPrimary);
    //btnClss3.x = 61;
    break;
   case "btnClss4" :
    stage.removeChild(addToll);
    //btnClss4.x = 61;
    break;
   case "btnClss5" :
    stage.removeChild(addEnd);
    //btnClss5.x = 61;
    break;
  }
 }
 
 //If all switches are present, show connections.
 if(allPresent >= 5)
 {
  mcConnections.alpha = 100;
 }
 else
 {
  mcConnections.alpha = 0;
 }
}
 

```
