title: Button Array and Switch Statement: ActionScript3
body: <p>I'm new to actionscript 3 (and this site) and I am having difficulty doing something that is probably very basic.  What I have is two movie clips on the stage that will act as buttons. I have named them btn1 and btn2. What I am trying to do is create an array of these "buttons" and add an Event Listener to each. When one button is clicked, you go to a particular frame. When the other is clicked you go to a different frame.  However, when I click btn1 I get "go to Frame 2" in the output window, which is incorrect.  I am not sure what I am doing wrong.</p>
  
  <p>On frame 1 I have the following:</p>
  
  <pre><code>import flash.events.MouseEvent;
  import flash.events.Event;
  
  stop();
  
  var buttons:Array = ["btn1","btn2"];
  
  
  for (var i:int =0; i &lt; buttons.length; i++)
  {
      var buttonName:Object = buttons[i];
      this.addEventListener(MouseEvent.CLICK, onButtonClicked);
      trace(buttonName);
  }
  
  function onButtonClicked(event:MouseEvent):void
  {
      switch (buttonName)
      {
          case "btn1" :
              trace("go to frame 1");
              break;
          case "btn2" :
              trace("go to frame 2");
              break;
          default :
              break;
      }
  }
  </code></pre>