# Variable.addEventListener OR dynamicVariable.addEventListener

**URL:** <https://forum.kirupa.com/t/variable-addeventlistener-or-dynamicvariable-addeventlistener/277835>\
**Category:** flash\
**Created:** [December 17, 2008, 9:45pm UTC](https://forum.kirupa.com/t/variable-addeventlistener-or-dynamicvariable-addeventlistener/277835 "2008-12-17T21:45:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MadTurki](https://avatars.discourse-cdn.com/v4/letter/m/278dde/32.png) [@MadTurki](https://forum.kirupa.com/u/MadTurki)\
**Post date:** [December 17, 2008, 9:45pm UTC](https://forum.kirupa.com/t/variable-addeventlistener-or-dynamicvariable-addeventlistener/277835/1 "2008-12-17T21:45:14Z")

</div>

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!

```auto

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!
