wondering about group touch events and children touch events

I have a display group that has a touch event on it so I can move the object around the screen as it’s touched. This group has children that I want to fire custom events from and bubble them up.

the code looks something like this.

[lua]local group = display.newGroup()
local function onTouch(event)
if event.phase == “began” then
display.getCurrentStage():setFocus(event.target, event.id)
elseif event.phase == “moved” then
–do something
elseif event.phase == “ended” then
display.getCurrentStage():setFocus(event.target, nil)
end
end

group:addEventListener(“touch”, onTouch)
local function buttonClicked(event)
–here i dispatch another custom event to the groups parent
local e = {name=“someevent”, value=“something”}
group:dispatchEvent(e)
end

local my_bn = Button:new()
my_bn:addEventListener(“customEvent”, buttonClicked)

group:insert(my_bn)

return group[/lua]

The issue I am having is that after the button that is inside the group is clicked the only part of the event phase that is triggered is the “began” phase and the custom event is never heard and caught in the buttonClicked function.

I come from a Flash background and this used to be any issue with Movieclips back in the day. You could not listen for click events on objects that where inside of a sprite or movieclip that had event listening applied to it. Is this the same case for corona ? [import]uid: 7501 topic_id: 17924 reply_id: 317924[/import]

Would it be possible for you to provide some plug and play code, please? If you can do that someone should be able to take a look and offer you some solid guidance.

You can listen for click events on sprites with Corona, that’s not a problem.

Peach :slight_smile: [import]uid: 52491 topic_id: 17924 reply_id: 68544[/import]

I actually solved the issue.

On the “group” touch’s began phase I was setting the following

[lua]display.getCurrentStage():setFocus(event.target, event.id)[/lua]

I moved this line of code to run on the moved phase. This way if a user touches a button inside of the group and the move phase doesn’t fire it allows for the touch events for the child button to run. Other wise I suppose when you setFocus it causes child events to be ignored or stops them.

[import]uid: 7501 topic_id: 17924 reply_id: 68565[/import]