Variable.addEventListener OR dynamicVariable.addEventListener

This is my first post on these forums though I’ve appreciated tons and tons of help from others that have posted their questions (and answers). I’m trying to dynamically create a menu based on the number of entries in an xml file. I need to create a button for each entry which then triggers a function through an eventListener. So I need to either dynamically name my movieClips I’m creating (for my buttons) OR find a way to take “tempName = mc.name” and then use that in tempName.addEventListener.

The relavent code is below! Thanks for the help!


function drawImage(i) {
   for (var item:int = 0; item < i; item++) {
   objectType = myXML.slide[item].objectType;

   if (objectType == "image") {
    dataPath =   myXML.slide[item].src;
 
    var mc:MovieClip = new MovieClip();
    imageMaster.addChild(mc);
    mc.graphics.beginFill(0x00000);
    mc.graphics.drawRect(wide*100 - 100, high*50, 40, 40);
    mc.graphics.endFill();
    mc.name = "mc"+item;
    
    mc.addEventListener(MouseEvent.MOUSE_UP,function(evt:MouseEvent){switchSlide(dataPath)});

   }
  }
}

The code does create all the buttons but when I click on any of the buttons the action performed is the action intended for the last button.

Thanks again!