title: Best Practices for Suspending Buttons in Actionscript 3
body: <p>Is there a better way to set up a flash project with lots of navigation than having to do this?:</p>
  
  <pre><code>bottomNav.contact_btn.addEventListener(MouseEvent.CLICK, changeContent);
  bottomNav.portfolio_btn.addEventListener(MouseEvent.CLICK, changeContent);
  bottomNav.news_btn.addEventListener(MouseEvent.CLICK, changeContent);
  bottomNav.inspiration_btn.addEventListener(MouseEvent.CLICK, changeContent);
  bottomNav.home_btn.addEventListener(MouseEvent.CLICK, changeContent);
  
  
  secondaryNav.about_btn.addEventListener(MouseEvent.CLICK, changeContent);
  secondaryNav.services_btn.addEventListener(MouseEvent.CLICK, changeContent);
  secondaryNav.home_btn.addEventListener(MouseEvent.CLICK, changeContent);
  
  secondaryNav.inspiration_btn.addEventListener(MouseEvent.CLICK, changeContent);
  secondaryNav.inspiration_archive_btn.addEventListener(MouseEvent.CLICK, changeContent);
  secondaryNav.portfolio_showcase_btn.addEventListener(MouseEvent.CLICK, changeContent);
  secondaryNav.portfolio_archive_btn.addEventListener(MouseEvent.CLICK, changeContent);
  </code></pre>
  
  <p>and if not, there are always moments between animations where the last thing you want to happen is for someone to click a button and have another function fire off in the middle of your beautiful wipe between two scenes.  You end up with (or at least I do) countless errors and a pissed off client.  </p>
  
  <p>What do you do to suspend all of those listeners without adding a function to the end of every other function to temporarily disable them?</p>
  
  <p>Please, if someone has the magic practice, I'd love to hear it.  </p>
  
  <p>in regards to how I do it I've been writing something like this:</p>
  
  <pre><code>function suspendBtns():void
  {
  secondaryNav.inspiration_archive_btn.removeEventListener(MouseEvent.CLICK, changeContent);
  secondaryNav.portfolio_showcase_btn.removeEventListener(MouseEvent.CLICK, changeContent);
  secondaryNav.portfolio_archive_btn.removeEventListener(MouseEvent.CLICK, changeContent);
  
  }
  </code></pre>
  
  <p>and would add <code>suspendBtns()</code>; to the end of every function that would transition between clips.<br>
  then obviously another function called <code>enactBtns()</code> or something like that.</p>
  
  <p>I tried once just adding one event listener to the stage:</p>
  
  <pre><code>stage.addEventListner(MouseEvent.CLICK, doFunction);
  </code></pre>
  
  <p>and then the function would find the name of the btn like:</p>
  
  <pre><code>function doFunction(e:Event):void{
  
   switch(e.target.name){     
      case"home_btn":
      doThis();
      break;
  
      case"away_btn":
      doThat();
      break;
  
    }
  
  }
  </code></pre>
  
  <p>and so on.  That didn't work so well, it felt as though I had to click every button twice to get it to work.  </p>
  
  <p>And I still had to suspend the event listener in between actions.</p>