Widget Scroller Help

Hi! I’m having trouble with the widget scroller. I’ll show you my code and explain my problem, and hopefully you can help. :slight_smile:

[lua]local scroller = widget.newScrollView{
top = 50,
height = 430,
scrollWidth = 320,
scrollHeight = 1800,
maskFile = “bitmapMask.png”,
bgColor = { 255, 255, 255, 0 },
}

local bladesbuttonfunction = function( 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
scroller:takeFocus( event )
end
elseif event.phase == “release” then
–some random stuff here…
end
return true
end

local bladesbutton = widget.newButton{
default = “bladesgreybutton.png”,
over = “bladesgreybuttonD.png”,
width = 80,
height = 87,
onEvent = bladesbuttonfunction,
}
bladesbutton.x = 60
bladesbutton.y = 115

scroller:insert(bladesbutton.view)[/lua]

So there it is… Everything is working as it did before I tried to include scrolling, except for the scrolling. When I click the button and try to drag it nothing happens and I get a runtime error in the terminal. It seems like the terminal prints the error once for every pixel I try to drag the button. Here’s the error:

Runtime error
/Users/nathanballi/Desktop//settingsmenu.lua:125: attempt to call method ‘takeFocus’ (a nil value)
stack traceback:
[C]: in function ‘takeFocus’
/Users/nathanballi/Desktop//settingsmenu.lua:125: in function ‘onEvent’
?: in function <?:90>
?: in function <?:215>

I hope you can help. Thanks!!

Nathan

I forgot to mention another problem. In the code above you'll notice that I've set the scroller height to an amount other then 480. I did this because I want to fill the extra space with a back button so it always remains in view. The problem is, when I scroll, everything that is being "scrolled" goes over the back button instead of behind. The back button is not overlapping the maskFile. How is this fixed?  
  
Nathan [import]uid: 39302 topic\_id: 25529 reply\_id: 325529[/import]
  1. scrollView:takeFocus() is exclusive to build 721+, which you don’t have access to as a test driver. You’d have to either wait for the next public release or play around with the typical way of setting focus…

  2. You’re not inserting the button into a display group. What I would do is:

local function bladesButton() local group = display.newGroup() -- create the scrollview -- create the button group:insert(scrollView) group:insert(button) -- create the event function return group -- by typing this, whatever variable you give to bladesButton() is now the displaygroup. end

That way you could type local mysetup = bladesButton() and could then manipulate the group however you want.

Maybe it’s just a typo, but the way your code is currently setup it looks like it will create the button whenever there is an event triggered, which is a bit scary… [import]uid: 41884 topic_id: 25529 reply_id: 103306[/import]

Thanks. So I don’t have the right build right now, but if I did, does it look like it would work?

P.S. The button is okay. :slight_smile: [import]uid: 39302 topic_id: 25529 reply_id: 103307[/import]

Maybe? It’s hard to say because I don’t understand what the function connects to. Right now all I can tell is that you have a touch event function that at some point will:

  1. do a focus test (may or may not grant focus), and also…
  2. create a button [import]uid: 41884 topic_id: 25529 reply_id: 103345[/import]

Okay, now that you’ve fixed the format…

Not sure how widget.newButton works (I don’t use it), but if you do end up with a build that’s .721+, I believe you no longer need to add .view. The rest seems to make sense. [import]uid: 41884 topic_id: 25529 reply_id: 103361[/import]

Okay. I was wondering about that. I did jut get it to work, so thanks a ton for your time! I really appreciate it.

Nathan [import]uid: 39302 topic_id: 25529 reply_id: 103370[/import]

Hi again. I’m official now. :slight_smile: I don’t get the error any more, but the scrollView doesn’t scroll when I drag a button. Am I forgetting something? I still have the same code as above.
Thanks [import]uid: 39302 topic_id: 25529 reply_id: 105808[/import]

You can’t drag if you begin on the button, because “return true” prevents the press from reaching the scrollView below. [import]uid: 41884 topic_id: 25529 reply_id: 105820[/import]

The scrolling works fine now, but the button remains the “over” image and none of the elseif statements take effect. I’ve tried a couple things to solve this, but nothing has worked yet. [import]uid: 39302 topic_id: 25529 reply_id: 105914[/import]

Did you get it working? [import]uid: 41884 topic_id: 25529 reply_id: 106075[/import]

Not yet. Any advice or tips? [import]uid: 39302 topic_id: 25529 reply_id: 106129[/import]

Can you post the scrollview and button code? just need those bits [import]uid: 41884 topic_id: 25529 reply_id: 106132[/import]

No problem.

[lua]local scroller = widget.newScrollView{
top = 50,
height = 430,
scrollWidth = 320,
scrollHeight = 1800,
maskFile = “bitmapMask.png”,
bgColor = { 255, 255, 255, 0 },
}
local bladesbuttonfunction = function( 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
scroller:takeFocus( event )
end
elseif event.phase == “release” then
scores:store(“BladeColorValue”, 0)
scores:save()
bluecircle.isVisible = true
bluecircle.x = W/2
bluecircle.y = 107.5 + 45.5
end
–return true
end

local bladesbutton = widget.newButton{
default = “bladesbutton.png”,
over = “bladesbuttonD.png”,
width = 80,
height = 87,
onEvent = bladesbuttonfunction,
}
bladesbutton.x = W/2
bladesbutton.y = 115 + 45.5

scroller:insert(bladesbutton.view)[/lua]

I think everything’s the same. [import]uid: 39302 topic_id: 25529 reply_id: 106143[/import]

Yeah…so…it’s what I feared and you really should file a bug about it. I don’t think Ansca’s really interested in my opinion on this one again. Hell, here’s the code you should file it with:

[code]-- main.lua
local scroller = widget.newScrollView{
bgColor = { 255, 255, 255, 0 },
}

local buttonPress = function( 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
scroller:takeFocus( event )
end
elseif event.phase == “release” then
print(“event.phase”, event.phase)
end
end

local button = widget.newButton{
width = 100,
height = 100,
onEvent = buttonPress,
}
button.x = display.contentWidth/2
button.y = display.contentHeight/2

scroller:insert(button)[/code]

(First off, a bug; you don’t need to insert .view anymore.)

Basically, widget.newScrollView() eats the “ended” event.phase and instead gives you event.type things instead. Which is a problem because widget.newButton() is looking for “ended”.

So your only choice is to either make your own buttons or use return true and give up on your button releasing the press phase. (TBH making your own button shouldn’t be that hard…) [import]uid: 41884 topic_id: 25529 reply_id: 106158[/import]

I’ve never reported a bug before, so I’m really not sure what I’m doing. I know you have your own life :slight_smile: but could you give me the “Bug description” they ask for? [import]uid: 39302 topic_id: 25529 reply_id: 106201[/import]

Something like this?

_widget.newButton() does not work properly when existing within widget.newScrollView().

widget.newButton() requires a touch end phase (“release”) in order to visually release the button, but since newScrollView() swallows this phase - using event.type instead of event.phase - there’s no way to bridge the new widgets._

The idea is just to try and concisely describe the problem. In repro steps you would quickly walk through what you would expect (probably based on the sample code you provide). [import]uid: 41884 topic_id: 25529 reply_id: 106542[/import]