how to put addEventListeners in a loop

hello

I have been trying to understand this. After some study I came up with this simple code.

I have a table and 1 image, and I declare that first

local myVariable = {} local image

then I create both of them

    -- just 14 numbers     local extra = 1     for i = 1, 14 do     myVariable[i] = display.newText( sceneGroup, "1", 0, 0, native.systemFont, 30 )     myVariable[i].x = 100 + i\*50     myVariable[i].y = display.contentCenterY     myVariable[i]:setFillColor( 1, 1, 1 )     myVariable[i].isVisible = true     extra = extra + 1     end     myVariable[2].text = "2"     myVariable[3].text = "3"          -- image here     image = display.newImageRect ( sceneGroup, "images/mGreen.jpg", 112, 112)     image.x = display.contentCenterX     image.y = display.contentCenterY + 200     image:scale (.65, .65)     image.isVisible = true

later in my code in the show scene i have a “touch” function

    function image:touch( event )     if event.phase == "began" then         -----------------         -- // CODE GOES HERE         -- // CODE ENDS HERE         -------------------         -- set touch focus         display.getCurrentStage():setFocus( self )         self.isFocus = true     elseif self.isFocus then         if event.phase == "moved" then                 -----------------         elseif event.phase == "ended" or event.phase == "cancelled" then                 -----------------         -- // CODE GOES HERE         image.rotation = 45         -- // CODE ENDS HERE         -------------------             -- reset touch focus             display.getCurrentStage():setFocus( nil )             self.isFocus = nil         end     end     return true     end     image:addEventListener( "touch", image )

so when i “touch” the image the image rotates.

QUESTION:

how can I add an eventListener in the loop to ALL of the numbers at once? with 1 line.

and then later how can I manipulate in 1 function only but make a difference

if it’s number 3

– image.rotate

if is number 7

– image.change color

and so on


I try, the ( self, event )

or

myVariable[3]:addEventListener( “touch”, myVariable[3] )

or

local obj = event.target

but I just can not make it to work.

Please I need your help to solve this problem, I think I am really close

but I do need your help, thanks everyone for your time.

Victor