Automatically trigger a tap event?

Say I’ve created a display object, a function to handle tap events on that object, and have bound the function to the event like this:

obj:addEventListener('tap', tapEvent)

Is there a simple function to then later trigger that tapEvent as if the user did just tap on the object?

Presumably I could construct a fake event table with things like target, x, y, etc properties and pass this to the defined function, like this:

tapEvent({ target = obj, x = 0, y = 0 })

But this doesn’t feel like the right approach. I’m hoping there’s something more like an obj:invokeEventListener(‘tap’) that I just haven’t found yet?

You could dispatch an event like this:

[lua]

obj:dispatchEvent( {name=“tap”, target=obj} )

[/lua]

Dave

Perfect, thanks Dave. Looked dispatchEvent up and that’s exactly what I was looking for :grin:

You could dispatch an event like this:

[lua]

obj:dispatchEvent( {name=“tap”, target=obj} )

[/lua]

Dave

Perfect, thanks Dave. Looked dispatchEvent up and that’s exactly what I was looking for :grin: