[resolved] scrollview problem

I have scrollview widget with one child (myrect)

I want to detect the touch ended event for “myrect” however currently it only detects the “began” phase !!

here is the complete code

  
--main.lua  
local widget = require "widget"  
  
local myscrollview = widget.newScrollView{}  
  
local myrect = display.newRect(0, 0, display.contentWidth, 68)   
myrect:setFillColor(255,100,100,255)  
myscrollview:insert(myrect)  
  
local function ontouch(event)  
  
 if event.phase == "ended" then  
 print("event ended")  
 end  
end  
myrect:addEventListener( "touch", ontouch )  

what I need is a basic functionality it is strange that corona does not support that or maybe I am missing something
Many thanks [import]uid: 8519 topic_id: 26351 reply_id: 326351[/import]

You need to “return true” at the end of your touch handler

[code]
local widget = require “widget”

local myscrollview = widget.newScrollView{}

local myrect = display.newRect(0, 0, display.contentWidth, 68)
myrect:setFillColor(255,100,100,255)
myscrollview:insert(myrect)

local function ontouch(event)

if event.phase == “ended” then
print(“event ended”)
end

return true
end
myrect:addEventListener( “touch”, ontouch )
[/code] [import]uid: 84637 topic_id: 26351 reply_id: 106809[/import]

WOW Danny it works like a charm!!!
Many Thanks [import]uid: 8519 topic_id: 26351 reply_id: 106817[/import]

Just in case if someone interested here is the enhanced version of the same code

Thanks to Danny and Jonathan Beebe for this helpful workaround https://gist.github.com/1590908

[code]
local widget = require “widget”

local myscrollview = widget.newScrollView{}

local myrect = display.newRect(0, 0, display.contentWidth, 68)
myrect:setFillColor(255,100,100,255)
myscrollview:insert(myrect)

local function ontouch(event)

if event.phase == “moved” then
local dx = math.abs( event.x - event.xStart )
local dy = math.abs( event.y - event.yStart )

if dx > 5 or dy > 5 then
myscrollview:takeFocus( event )
end
elseif event.phase == “ended” then
display.getCurrentStage():setFocus(nil)
print(“event ended”)
end

return true
end
myrect:addEventListener( “touch”, ontouch )
[/code] [import]uid: 8519 topic_id: 26351 reply_id: 107773[/import]

Been looking for a workaround for this issue for some time now. None of the solutions I tried worked the way I wanted it to. Thank you for posting this!!! [import]uid: 44153 topic_id: 26351 reply_id: 119554[/import]

Your all welcome, just to be clear this isn’t a workaround. This behavior should be applied to any object that has a touch event, where you don’t want the touch event leaking through to the objects below.

[import]uid: 84637 topic_id: 26351 reply_id: 119579[/import]

Been looking for a workaround for this issue for some time now. None of the solutions I tried worked the way I wanted it to. Thank you for posting this!!! [import]uid: 44153 topic_id: 26351 reply_id: 119554[/import]

Your all welcome, just to be clear this isn’t a workaround. This behavior should be applied to any object that has a touch event, where you don’t want the touch event leaking through to the objects below.

[import]uid: 84637 topic_id: 26351 reply_id: 119579[/import]