Table listener in Corona

Introduction :
Table listener is the one of the way to define listener for any display object in corona.

Description :
To describe table listener, lets have a window with a rectangle box and will add table listener with that box to show message on console.

CODE BLOCK :

main.lua
local myBox = display.newRect( 100, 100, 200, 100)

On above, I have defined a rectangle using newRect function which accepts four parameters.
The first and second parameter hold the x and y cordinates as the base postion for the box and the next two parameters define the width and height respectively.

myBox:setFillColor(121,121,121) --Define background color of the box.

-- Define table listener for the box
function myBox:touch( event )

   -- Print on consele
   print( 'Function listener called!' )

end

 Here on above a function is defined which will print message on console.

myBox:addEventListener( 'touch', myBox)   -- Listener added with touch event

Now on touch of the above rectangle the ‘functionListener’ will be called every time

Summary : Here we have an example, how to bind table listener with any display object.
NOTE : Tested in iOS and Android device.

150 150 Burnignorance | Where Minds Meet And Sparks Fly!