Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Automatically trigger a tap event?
Started by richard11 Apr 08 2019 01:16 PM

2 replies to this topic
events
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 475 posts
  • Corona SDK

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?



[TOPIC: post.html]
#2

Quantumwave

[GLOBAL: userInfoPane.html]
Quantumwave
  • Contributor

  • 103 posts
  • Corona SDK

You could dispatch an event like this:

 

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

 

Dave

 



[TOPIC: post.html]
#3

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 475 posts
  • Corona SDK

Perfect, thanks Dave. Looked dispatchEvent up and that's exactly what I was looking for 😁


[topic_controls]
[/topic_controls]