Yea, I have 2 buttons on scroll view. They only register event.phase “began” and not any else. The handle button event has return true at the end.
Anyone?
Coder 101
Yea, I have 2 buttons on scroll view. They only register event.phase “began” and not any else. The handle button event has return true at the end.
Anyone?
Coder 101
That is correct. The scrollview takes focus, so the button doesn’t get any more events.
My hope is someone else will respond with a simple solution, but I did solve this for my own uses.
I did so, by wrapping the entire creation process and co-opting the scroll listener to pass touch events on to buttons.
It’s been awhile since I tested this aspect specifically, but the ScrollView shouldn’t take focus away unless you tell it to via the “:takeFocus()” API. I think we’ll have to see some code to decipher what exactly is going on…
Brent
hummm. I use objects with touch events all the time inside scrollViews and never gave me a problem. just tested one of my codes to check if they have all 3 event phases and they have (“began”, “moved”, “ended”)
i use this function to add touch events on objects:
function menu.addTouch (parametros) local params=parametros or {} local obj = params.obj or nil if not obj then print ("needs an object to add touch event") return nil end local func=params.func or nil local alphaInicial = params.alpha or obj.alpha local alphaPressed = params.alphaPressed or 1 local scrollView=params.scrollView or nil local return\_self=params.return\_self or false local color\_selected=params.color\_selected or nil local color=params.color or nil local function touch(self, event) print (event.phase) if event.phase == "began" then display.getCurrentStage():setFocus( self, event.id ) self.isFocus = true self.alpha=alphaPressed if color and color\_selected then self:setFillColor(unpack(color\_selected)) end elseif self.isFocus then if event.phase == "moved" then if scrollView then local dy = math.abs( ( event.y - event.yStart ) ) if ( dy \> 5 ) then scrollView:takeFocus( event ) self.alpha=alphaInicial if color and color\_selected then self:setFillColor(unpack(color)) end end end elseif event.phase == "ended" or event.phase == "cancelled" then self.alpha=alphaInicial display.getCurrentStage():setFocus( self, nil ) self.isFocus = false if color and color\_selected then self:setFillColor(unpack(color)) end if func then if return\_self then func(self) else func() end end end end return true end obj.touch = touch obj:addEventListener( "touch", obj ) end
you just need to use like this:
menu.addTouch({obj=object, func=callFunction, scrollView=scrollView})
object, is the object to add touch event,
callFunction, is the function to call when button is pressed and released without moving the mouse/finger (<5px)
scrollView, is the scrollView object that the button is inside. if you move the mouse/finger while pressing more than 5px it will return focus to scrollView. this way objects inside scrollViews will not be “stuck” when you press them and scroll on scrollView will work like that object doesn’t have a touch event and didn’t stopped the scrollview…
hope I explained it “good enough”, my English is not great…i know 
Fixed it! The error was that I had one function and then added listener for every button for that function. They were table listeners. In my for loop when every button is created I create also local listener item touch. So it works now! Thanks anyways for answering!! 
Coder 101
That is correct. The scrollview takes focus, so the button doesn’t get any more events.
My hope is someone else will respond with a simple solution, but I did solve this for my own uses.
I did so, by wrapping the entire creation process and co-opting the scroll listener to pass touch events on to buttons.
It’s been awhile since I tested this aspect specifically, but the ScrollView shouldn’t take focus away unless you tell it to via the “:takeFocus()” API. I think we’ll have to see some code to decipher what exactly is going on…
Brent
hummm. I use objects with touch events all the time inside scrollViews and never gave me a problem. just tested one of my codes to check if they have all 3 event phases and they have (“began”, “moved”, “ended”)
i use this function to add touch events on objects:
function menu.addTouch (parametros) local params=parametros or {} local obj = params.obj or nil if not obj then print ("needs an object to add touch event") return nil end local func=params.func or nil local alphaInicial = params.alpha or obj.alpha local alphaPressed = params.alphaPressed or 1 local scrollView=params.scrollView or nil local return\_self=params.return\_self or false local color\_selected=params.color\_selected or nil local color=params.color or nil local function touch(self, event) print (event.phase) if event.phase == "began" then display.getCurrentStage():setFocus( self, event.id ) self.isFocus = true self.alpha=alphaPressed if color and color\_selected then self:setFillColor(unpack(color\_selected)) end elseif self.isFocus then if event.phase == "moved" then if scrollView then local dy = math.abs( ( event.y - event.yStart ) ) if ( dy \> 5 ) then scrollView:takeFocus( event ) self.alpha=alphaInicial if color and color\_selected then self:setFillColor(unpack(color)) end end end elseif event.phase == "ended" or event.phase == "cancelled" then self.alpha=alphaInicial display.getCurrentStage():setFocus( self, nil ) self.isFocus = false if color and color\_selected then self:setFillColor(unpack(color)) end if func then if return\_self then func(self) else func() end end end end return true end obj.touch = touch obj:addEventListener( "touch", obj ) end
you just need to use like this:
menu.addTouch({obj=object, func=callFunction, scrollView=scrollView})
object, is the object to add touch event,
callFunction, is the function to call when button is pressed and released without moving the mouse/finger (<5px)
scrollView, is the scrollView object that the button is inside. if you move the mouse/finger while pressing more than 5px it will return focus to scrollView. this way objects inside scrollViews will not be “stuck” when you press them and scroll on scrollView will work like that object doesn’t have a touch event and didn’t stopped the scrollview…
hope I explained it “good enough”, my English is not great…i know 
Fixed it! The error was that I had one function and then added listener for every button for that function. They were table listeners. In my for loop when every button is created I create also local listener item touch. So it works now! Thanks anyways for answering!! 
Coder 101