ScrollView with buttons doesn't work properly

Hi everyone,

I’m going crazy with a scrollview. I’ve some buttons that I want to scroll and everything was going fine but now the onRelease option doesn’t work. So the buttons scroll, but when pressed nothing happens. Where I’m going wrong? Thank you in advance!

 local titleBar = display.newImageRect(myApp.topBarBg, display.contentWidth, 50) titleBar.x = display.contentCenterX titleBar.y = 25 + display.topStatusBarContentHeight group:insert(titleBar) -- -- set up the text for the title bar, will be changed based on what page -- the viewer is on local function listener( event ) local shouldLoad = true local url = event.url if 1 == string.find( url, "corona:close" ) then -- Close the web popup shouldLoad = false end if event.errorCode then -- Error loading page print( "Error: " .. tostring( event.errorMessage ) ) shouldLoad = false end return shouldLoad end local options = { hasBackground=false, baseUrl=system.DocumentsDirectory, urlRequest=listener } titleText = display.newText( "Uffici", 0, 0, GillSans, 20 ) titleText:setTextColor( 255, 255, 255 ) titleText:setReferencePoint( display.CenterReferencePoint ) titleText.x = display.contentCenterX titleText.y = titleBar.height \* 0.5 + display.topStatusBarContentHeight group:insert(titleText) backButton = widget.newButton({ width = 59, height = 32, defaultFile = "images/backbutton7\_white.png", overFile = "images/backbutton7\_white.png", effect = "slideLeft", time = 800, onRelease = myApp.showScreen03, }) backButton.y = titleBar.y backButton.x = 32 group:insert(backButton) -- Our ScrollView listener local function scrollListener( event ) local phase = event.phase local direction = event.direction if "began" == phase then print( "Began" ) elseif "moved" == phase then print( "Moved" ) elseif "ended" == phase then print( "Ended" ) end -- If we have reached one of the scrollViews limits if event.limitReached then if "up" == direction then print( "Reached Top Limit" ) elseif "down" == direction then print( "Reached Bottom Limit" ) elseif "left" == direction then print( "Reached Left Limit" ) elseif "right" == direction then print( "Reached Right Limit" ) end end return true end local scrollView = widget.newScrollView { top = 70, left = 0, width = 320, height = 380, scrollWidth = 465, scrollHeight = 900, } local function buttonTouch( event ) local phase = event.phase if "moved" == phase then local dy = math.abs( ( event.y - event.yStart ) ) -- If our finger has moved more than the desired range if dy \> 10 then -- Pass the focus back to the scrollView scrollView:takeFocus( event ) end end return true end local button1 = widget.newButton({ width = 320, height = 85, label = "", defaultFile = "amministrativa.png", overFile = "amministrativa\_over.png", labelYOffset = -4, font = myApp.font, fontSize = 18, emboss = false, onTouch = myApp.showScreen04, onEvent = buttonTouch }) scrollView:insert(button1) button1.y = 0 local button2 = widget.newButton({ width = 320, height = 85, label = "", defaultFile = "ata.png", overFile = "ata\_over.png", labelYOffset = -4, font = myApp.font, fontSize = 18, emboss = false, onEvent = buttonRelease, onTouch = myApp.showScreen06 }) scrollView:insert(button2) button2.y = 85 local button3 = widget.newButton({ width = 320, height = 85, label = "", defaultFile = "finanziaria.png", overFile = "finanziaria\_over.png", labelYOffset = -4, font = myApp.font, fontSize = 18, emboss = false, onTouch = myApp.showScreen02, onEvent = handleButtonEvent, }) scrollView:insert(button3) button3.y = 170 local button4 = widget.newButton({ width = 320, height = 85, label = "", defaultFile = "lavoripubblici.png", overFile = "lavoripubblici\_over.png", labelYOffset = -4, font = myApp.font, fontSize = 18, emboss = false, onTouch = myApp.showScreen02, onEvent = buttonTouch }) scrollView:insert(button4) button4.y = 250 local button5 = widget.newButton({ width = 320, height = 85, label = "", defaultFile = "lavoripubblici.png", overFile = "lavoripubblici\_over.png", labelYOffset = -4, font = myApp.font, fontSize = 18, emboss = false, onRelease = myApp.showScreen02, onEvent = buttonTouch }) scrollView:insert(button5) button5.y = 335 group:insert(scrollView) end function scene:destoryScene( event ) local group = self.view end

Nobody can help me? Sorry if I bump but it’s important for me… @staff: I don’t know why but there are two topics made by me, could you please erase the other one? Thanks

You need to use the scrollviews takeFocus() function to pass focus from the scrollview to your buttons:

Please see here: http://docs.coronalabs.com/api/type/ScrollViewWidget/takeFocus.html

Thanks Danny but, as you can see in the code, I’ve implemented yet the takeFocus… so buttons can scroll but nothing happens when I tap on them. I don’t understand what I’m doing wrong, please could you help me with the code? Thanks 

Sorry.

Ok so there is no “onTouch” parameter for widget buttons.

There are:

onEvent, onPressed and onReleased.

You should remove the onTouch reference and just call your function inside the began event of your onEvent listener.

Hope that makes sense

Nobody can help me? Sorry if I bump but it’s important for me… @staff: I don’t know why but there are two topics made by me, could you please erase the other one? Thanks

You need to use the scrollviews takeFocus() function to pass focus from the scrollview to your buttons:

Please see here: http://docs.coronalabs.com/api/type/ScrollViewWidget/takeFocus.html

Thanks Danny but, as you can see in the code, I’ve implemented yet the takeFocus… so buttons can scroll but nothing happens when I tap on them. I don’t understand what I’m doing wrong, please could you help me with the code? Thanks 

Sorry.

Ok so there is no “onTouch” parameter for widget buttons.

There are:

onEvent, onPressed and onReleased.

You should remove the onTouch reference and just call your function inside the began event of your onEvent listener.

Hope that makes sense