Manually Dispatched Event Not Propagating

Hi all,

I’m dispatching a manual “touch” event via foo:dispatchEvent(e).  The handler for foo is triggered properly by the custom event, but the event isn’t propagated if foo’s handler returns false.

Am I doing something wrong?

Below is the code I’m using to generate the custom event:

local newEvent = {} newEvent.name = "touch" newEvent.phase = "began" newEvent.x = event.xStart newEvent.y = event.yStart newEvent.xStart = event.xStart newEvent.yStart = event.yStart newEvent.target = event.target event.target:dispatchEvent(newEvent)

Also tried Runtime:dispatchEvent(e) but that doesn’t hit the handler at all.

Thx.

Hi @ddubya82,

I assume what you mean is, you want a “pseudo touch” to propagate through a series of display objects, as if they were actually touched by a real touch on the screen? Unfortunately, “object:dispatchEvent()” doesn’t fully extend to that level of “real touch” with all of the behavior of propagating through the display hierarchy as if it was an actual touch… basically, its use is to give a sort of one-off pseudo touch/tap or other event trigger to an object in specific cases.

Best regards,

Brent

Understood.  I’m able to get around this by calling the other handler directly but was hoping I could just let Corona do its thing…

Any idea why Runtime:dispatchEvent isn’t hitting my handler?

Cheers.

That aspect should be working… can you show me the code you’re using?

Brent

Exact same as above, but calling Runtime instead of event.target:

local newEvent = {} newEvent.name = "touch" newEvent.phase = "began" newEvent.x = event.xStart newEvent.y = event.yStart newEvent.xStart = event.xStart newEvent.yStart = event.yStart newEvent.target = event.target Runtime:dispatchEvent(newEvent)

Hi @ddubya82,

It works fine for me. Obviously you need to add an event listener of the “name” to the Runtime as follows:

[lua]

local newEvent = {}

newEvent.name = “touch”

newEvent.phase = “began”

Runtime:addEventListener( “touch”,

    function()

        print( “OK!!!” )

    end

)

Runtime:dispatchEvent(newEvent)

[/lua]

Brent

Right… wasn’t changing the handler to Runtime.  Thx!

Hi @ddubya82,

I assume what you mean is, you want a “pseudo touch” to propagate through a series of display objects, as if they were actually touched by a real touch on the screen? Unfortunately, “object:dispatchEvent()” doesn’t fully extend to that level of “real touch” with all of the behavior of propagating through the display hierarchy as if it was an actual touch… basically, its use is to give a sort of one-off pseudo touch/tap or other event trigger to an object in specific cases.

Best regards,

Brent

Understood.  I’m able to get around this by calling the other handler directly but was hoping I could just let Corona do its thing…

Any idea why Runtime:dispatchEvent isn’t hitting my handler?

Cheers.

That aspect should be working… can you show me the code you’re using?

Brent

Exact same as above, but calling Runtime instead of event.target:

local newEvent = {} newEvent.name = "touch" newEvent.phase = "began" newEvent.x = event.xStart newEvent.y = event.yStart newEvent.xStart = event.xStart newEvent.yStart = event.yStart newEvent.target = event.target Runtime:dispatchEvent(newEvent)

Hi @ddubya82,

It works fine for me. Obviously you need to add an event listener of the “name” to the Runtime as follows:

[lua]

local newEvent = {}

newEvent.name = “touch”

newEvent.phase = “began”

Runtime:addEventListener( “touch”,

    function()

        print( “OK!!!” )

    end

)

Runtime:dispatchEvent(newEvent)

[/lua]

Brent

Right… wasn’t changing the handler to Runtime.  Thx!