title: Action Script: Call corresponding functions on button click
body: <p>I have been trying to add buttons dynamically and then assign event listeners to them. For which my code is,</p>
  
  <pre><code>    var i=0;
      var step=50;
      for each (var child:XML in courseXML.footer.tray.elements())
      {           
          var thumbClip:thumb = new thumb();
          //set name 
          thumbClip.name = "mc_thumb" + (i + 1);
          trace("thumbClipname:: "+thumbClip.name);
          //set the x and y values
          thumbClip.x = 620 + (i * step);
          thumbClip.y = 560;
  
          //attach the newly created instance to the container
          addChild(thumbClip);
          trace("thumbClip:: "+thumbClip);
  
          //attach icon image from xml path
          thumbClip.thumbLoader.source = child.icon;
          trace("thumbClip.thumbLoader.source: "+thumbClip.thumbLoader.source);
  
          //add listeners
          trace("Node name "+ child.localName());
          if(child.localName().toLowerCase() == "feedback");
          {   trace("gotoFeedback..");
              thumbClip.addEventListener(MouseEvent.CLICK, gotoFeedback);
          }
          if(child.localName().toLowerCase() == "resources");
          {   trace("gotoResources..");
              thumbClip.addEventListener(MouseEvent.CLICK, gotoResources);
          }
          if(child.localName().toLowerCase() == "glossary");
          {   trace("gotoGlossary..");
              thumbClip.addEventListener(MouseEvent.CLICK, gotoGlossary);
          }
          if(child.localName().toLowerCase() == "discussion");
          {   trace("gotoDiscussion..");
              thumbClip.addEventListener(MouseEvent.CLICK, gotoDiscussion);
          }
  
          thumbClip.buttonMode = true;
          i++;
      } 
  </code></pre>
  
  <p>So, Finally 4 buttons are displayed on stage and when I click on any button all the four functions <code>gotofeedback, gotoResources, gotoGlossary, gotoDiscussion</code> are called. How do I call corresponding functions on button click? Thanks!</p>
  
  <pre><code>The four functions are:
  function gotoFeedback(e: MouseEvent):void
  {
      trace("gotofeedback fn called..");
  }
  function gotoResources(e: MouseEvent):void
  {
      trace("gotoResources fn called..");
  }
  function gotoGlossary(e: MouseEvent):void
  {
      trace("gotoGlossary fn called..");
  }
  function gotoDiscussion(e: MouseEvent):void
  {
      trace("gotoDiscussion fn called..");
  }
  </code></pre>