Knowing which button was touched

Hi

I’ve got a function attached to 4 buttons.

button1:addEventListener( "touch", startDrag ) button2:addEventListener( "touch", startDrag ) button3:addEventListener( "touch", startDrag ) button4:addEventListener( "touch", startDrag )

How can I know, except for the part of visualy seeing it :), which button triggered the startDrag function?

The startDrag function goes like this:

local function startDrag( event, params ) local body = event.target local phase = event.phase local stage = display.getCurrentStage() local direction = event.direction if "began" == phase then ...

In your startDrag function the event variable will hold a reference to the object that was touched in event.target.

So when making your button you can assign a name to it, for example button1.name = ‘This is my first button’. It doesn’t have to be ‘name’, can be anything.

Then in your startDrag function  you can get the name of the button that was touched with: event.target.name

Hope that is clear.

Great, its working. Thank you for your help…

In your startDrag function the event variable will hold a reference to the object that was touched in event.target.

So when making your button you can assign a name to it, for example button1.name = ‘This is my first button’. It doesn’t have to be ‘name’, can be anything.

Then in your startDrag function  you can get the name of the button that was touched with: event.target.name

Hope that is clear.

Great, its working. Thank you for your help…