# Table object Event Listener

**URL:** <https://forums.solar2d.com/t/table-object-event-listener/293121>\
**Category:** Lua Language\
**Created:** [August 15, 2011, 3:36am UTC](https://forums.solar2d.com/t/table-object-event-listener/293121 "2011-08-15T03:36:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaspal\_2509](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/j/9fc29f/32.png) [@jaspal\_2509](https://forums.solar2d.com/u/jaspal_2509)\
**Post date:** [August 15, 2011, 3:36am UTC](https://forums.solar2d.com/t/table-object-event-listener/293121/1 "2011-08-15T03:36:52Z")

</div>

Hello All,

I am new to lua, and game development. However, I have made tremendous progress in last few days. I have question regarding table and event listener.

I have about 11 images in a table:

`local numbaFiles = { one="1.png", two="2.png", three="3.png", four="4.png", five="5.png", six="6.png",  
 seven="7.png", eight="8.png", nine="9.png", ten="10.png", eleven="11.png" }`

Then I created converted them into physics body and I also made them to appear randomly on the screen.

Now, I am trying to create an addEventListener to each of the image, so that when I click on an image it should react to the event.

I got it to work previously when I declared each image individually (local one=display.newImage(“1.png”). And used the following code to add an event and everything worked just fine.

```auto
nine.one:addEventListener("tap",runApp)
```

However, when I placed the images in the table everything got messed up. Images wont react to the “tap” event any more. I tried to change the code to

```auto
numbaFiles.one:addEventListener("tap", runApp)
```

But it did not work. Is there a different way of creating an event with table objects? I did read the documentation on the website but without any luck.  
I would appreciate any suggestion or help on this. thanks in advance.

[import]uid: 82666 topic\_id: 13847 reply\_id: 313847[/import]

---

<div class="post-metadata">

**Author:** ![darkconsoles](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/d/a183cd/32.png) [@darkconsoles](https://forums.solar2d.com/u/darkconsoles)\
**Post date:** [August 15, 2011, 3:48am UTC](https://forums.solar2d.com/t/table-object-event-listener/293121/2 "2011-08-15T03:48:07Z")

</div>

you can try numbaFiles[i]:addEventListener(“tap”, runApp) [import]uid: 16142 topic\_id: 13847 reply\_id: 50898[/import]

---

<div class="post-metadata">

**Author:** ![jaspal\_2509](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/j/9fc29f/32.png) [@jaspal\_2509](https://forums.solar2d.com/u/jaspal_2509)\
**Post date:** [August 15, 2011, 3:50am UTC](https://forums.solar2d.com/t/table-object-event-listener/293121/3 "2011-08-15T03:50:42Z")

</div>

Thanks for the reply. I tried it but it did not work. [import]uid: 82666 topic\_id: 13847 reply\_id: 50900[/import]

---

<div class="post-metadata">

**Author:** ![darkconsoles](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/d/a183cd/32.png) [@darkconsoles](https://forums.solar2d.com/u/darkconsoles)\
**Post date:** [August 15, 2011, 6:14am UTC](https://forums.solar2d.com/t/table-object-event-listener/293121/4 "2011-08-15T06:14:45Z")

</div>

you probably need to use “for” iterator,like:  
[lua]for i=1,5 --[[(or your number of objects in table)–]] table do  
object[i]:addEventListener(“touch”, function)  
end[/lua]  
this kind of thing should work [import]uid: 16142 topic\_id: 13847 reply\_id: 50911[/import]
