Quick question about touch events

Hi all,
I have a number of draggable objects that are stored in a table. When one of them is dragged I call a function that handles the event, but then when it is released (event.phase==ended) I would like to then call another function (explosion) with the name of the object that had been dragged so that the relevant action can take place. What I can’t figure out is how to tell the function what the name of the object is.

This the code I have for the touch event that is called by the event listeners.

[lua]function dragStuff(event)
if (event.phase==“began”) then
object.alpha=.5
object.xScale=.6
object.yScale=.6
elseif (event.phase==“moved”) then
object.x=event.x
object.y=event.y
if event.x<15 then
object.x=15
elseif event.y<15 then
object.y=15
elseif event.y>_h-15 then
object.y=_h-15
end
elseif (event.phase==“ended”) then
if (object.x>901) then
– Object is outside the play area and is returned to its original position.
transition.to(object,{ time=200, x = 962, y = 90, xScale=1, yScale=1, alpha=1})
else
– Here I would like to pass the name of the object dragged to another function.
end
end
end[/lua]
So instead of ‘object’ I could use a variable containing the name of the object that had been used.

I hope this all makes some kind of sense to someone.
[import]uid: 7841 topic_id: 17541 reply_id: 317541[/import]

What is the relevant action?

You could say something like;

[lua]myVar = event.target[/lua]

Is that the kind of thing you mean?

Sorry - I’m just trying to envision what you’d like to get happening here - could use a little more info.

Peach :slight_smile: [import]uid: 52491 topic_id: 17541 reply_id: 66902[/import]

Peach’s suggestion is the way to go about it [import]uid: 84637 topic_id: 17541 reply_id: 67221[/import]

Once again you are spot on Peach. I should have been able to work that one out. Sorry :slight_smile: [import]uid: 7841 topic_id: 17541 reply_id: 67543[/import]

Oh great! I was a tad confused about the goal but am very pleased it’s all good.

And don’t worry about not being able to work it out; we all have off days :wink:

Peach :slight_smile: [import]uid: 52491 topic_id: 17541 reply_id: 67698[/import]