Hello.
I would like to have 1 “touch” function for many objects.
I create 20 images in a loop – for i = 1 …
each object has a unique name, like a1, a2, a3 because i use a[i]
as far as I understand a touch function you put the name of the variable 3 times, like
function a1:touch( event ) if event.phase == "began" then audio.play(n44) -- 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 audio.stop ( ) -- reset touch focus display.getCurrentStage():setFocus( nil ) self.isFocus = nil end end return true end a1:addEventListener( "touch", a1 )
it works perfect, I touch a1 and plays the audio.
but how can I get the same function and make
a1 play audio 1
a2 play audio 2
a3 play audio 3 and so on…
Thanks for all your help, and I hope you can understand my question
Victor