Table object Event Listener

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.

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

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]

you can try numbaFiles[i]:addEventListener(“tap”, runApp) [import]uid: 16142 topic_id: 13847 reply_id: 50898[/import]

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

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]