title: AS3 Dynamically adding buttons to stage and accessing in different function
body: <p>I am trying to add multiple different versions of the same button to the stage and to be able to access them later on by assigning them an ID. The way I assumed this would be done is to have a class for the button where an internal static variable is defined so that the ID can be found in the next function. This does not seem to be working, as the ID is constantly showing as the last number given, so in this case 6.</p>
  
  <p>I assume that I am doing this wrong? Here is my code so you can better understand:</p>
  
  <pre><code>package src  {
  
  import flash.display.MovieClip;
  import flash.events.*;
  import flash.utils.Timer;
  import flash.net.*
  import flash.display.Loader
  
  public class main extends MovieClip {
  
  public var xmlData:XML = new XML
  public var currentName = null
  
      public function main() {
          var y = 0
          for(x=0; x&lt;=6; x++){
              var names:namez = new namez
              namez.ID = y
              y++
              names.y = x*25
              names.addEventListener(MouseEvent.CLICK, checkMe)
              spinner.addChild(names)
          }
      }
  
      public function checkMe(e:MouseEvent){
          trace("clicked"+namez.ID)
      }
  }
  }
  </code></pre>
  
  <p>namez.as class:</p>
  
  <pre><code>package src {
  
  import flash.display.MovieClip
  
  public class namez extends MovieClip{
  
      internal static var ID
  
      public function namez() {
      }
  
  }
  
  }
  </code></pre>
  
  <p>Despite doing a trace for the buttons for namez.ID and it correctly showing 0,1,2,3,4,5,6 when the button is clicked on, the only number that shows is 6.</p>
  
  <p>How do I correctly go about making dynamically added buttons accessable by other functions? Should I be using an array here?</p>
  
  <p>FYI the total number of buttons required is 241.</p>