# Using metadata to create listeners

**URL:** https://forum.kirupa.com/t/using-metadata-to-create-listeners/298542
**Category:** Uncategorized
**Created:** [October 20, 2009, 8:16pm UTC](https://forum.kirupa.com/t/using-metadata-to-create-listeners/298542 "2009-10-20T20:16:35Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![ooklamok](https://avatars.discourse-cdn.com/v4/letter/o/90db22/32.png) [@ooklamok](https://forum.kirupa.com/u/ooklamok)
#### Post date: [October 20, 2009, 8:16pm UTC](https://forum.kirupa.com/t/using-metadata-to-create-listeners/298542/1 "2009-10-20T20:16:35Z")

</div>

Hi, (I think this is in the wrong forum… sorry! Should be AS3)

I am trying to dynamically create listeners using metadata from a list of instance names in an array. Here is my code:  
[INDENT][SIZE=1]var menuItems:Array = new Array(“button1”,“button2”)[/SIZE]

[SIZE=1]for (var ele:String in menuItems)[/SIZE]  
[SIZE=1] {[/SIZE]  
[SIZE=1] [menuItems[ele]]addEventListener(MouseEvent.CLICK, PopUp); [/SIZE]  
[SIZE=1]}[/SIZE]

[SIZE=1]function PopUp(evt:MouseEvent):void[/SIZE]  
[SIZE=1]{[/SIZE]  
[SIZE=1] trace(evt.currentTarget.name);[/SIZE]  
[SIZE=1]}[/SIZE]  
[/INDENT]  
When the buttons are clicked, the trace shows “root1”.

Is there a way to make it pickup the actual name (button1 or button2)?

Thank you!
