Event bubbling

I have a some of questions regarding event bubbling, which I really hope to clarify:

  1. When using a TableView/ScrollView on 70% of the screen height (using a MaskFile and all that), and having buttons (images with touch events) on the remaining 30% of the screen, clicks to the buttons makes the TableView/ScrollView move IF THE TABLEVIEW/SCROLLVIEW HAS CONTENT THAT IS TALLER THAN THE VISIBLE SCREEN AREA. This must surely be a bug, since the buttons are outside the mask file area. Anyway, how to handle it?

  2. Should event handlers return true even if they didn’t handle the event? Some example code seems to suggest this:

function eventHandler(event)
if shouldHandleEvent()
handleEvent()
end
return true
end

I would imagine this would be more correct:

function eventHandler(event)
if shouldHandleEvent()
handleEvent()
return true
end
end

  1. This is related to question 2: Let’s say I want to handle event.phase “ended”. Should I return true only if I detect an “ended” phase, or should I return true when detecting “began” too?

  2. Do table listeners work better than function listeners for event handling? I seem to get more correct event calls and less propagation problems when I use table listeners.

– This seems to work better
function object:touch(event)
– handle the event
end
object:addEventListener(“touch”, object)

– This seems to work less good
function handler(event)
– handle the event
end
object:addEventListener(“touch”, handler)

Thanks in advance! [import]uid: 73434 topic_id: 31968 reply_id: 331968[/import]

Let me take a stab at it.


|      Other     |

       Area     
     Scroll     
      Area      

* Supposed to be the screen

[lua]local screen = display.newGroup ( )

local scrollArea = widget.newScrollView { width = screenW, height = screenH }
– Do other stuff to scroll view –
local otherArea = display.newRect ( 0, 0, screenW, 100 )

screen:insert ( scrollArea )
screen:insert ( otherArea )

local function scrollOnTouch ( event )
– do stuff
return true – Does not trigger events underneath current object
end

local function otherOnTouch ( event )
– do other stuff
return true – Does not trigger events underneath current object
– If the return wasn’t here it would trigger scrollOnTouch if it was underneath
end

scrollArea:addEventListener ( “touch”, scrollOnTouch )
otherArea:addEventListener ( “touch”, otherOnTouch )[/lua]

More Information Here:
http://developer.coronalabs.com/content/application-programming-guide-event-handling#Propagation_and_Handling_of_Events [import]uid: 7721 topic_id: 31968 reply_id: 127467[/import]

Let me take a stab at it.


|      Other     |

       Area     
     Scroll     
      Area      

* Supposed to be the screen

[lua]local screen = display.newGroup ( )

local scrollArea = widget.newScrollView { width = screenW, height = screenH }
– Do other stuff to scroll view –
local otherArea = display.newRect ( 0, 0, screenW, 100 )

screen:insert ( scrollArea )
screen:insert ( otherArea )

local function scrollOnTouch ( event )
– do stuff
return true – Does not trigger events underneath current object
end

local function otherOnTouch ( event )
– do other stuff
return true – Does not trigger events underneath current object
– If the return wasn’t here it would trigger scrollOnTouch if it was underneath
end

scrollArea:addEventListener ( “touch”, scrollOnTouch )
otherArea:addEventListener ( “touch”, otherOnTouch )[/lua]

More Information Here:
http://developer.coronalabs.com/content/application-programming-guide-event-handling#Propagation_and_Handling_of_Events [import]uid: 7721 topic_id: 31968 reply_id: 127467[/import]