scrollView:scrollToX() not working?

Hi Ansca,

I have been working with the updated (horizontal-scrolling) widget.newScrollView API, but for some reason I've yet to get the scrollToX method working properly. Anytime I call it, I get the following error message in the terminal:

1
2
Runtime error
        attempt to call method 'scrollToX' (a nil value)

Doesn't work for me either, was gonna post the problem but i'll just tack onto yours instead.

I have no problems using scrollToTop, Bottom etc, just X and Y.

It appears the method is not implemented???

"attempt to call method 'scrollToX' (a nil value)"

@mimetic: agreed, it would appear that this method, while referenced in the API docs online, is not actually baked into the current daily builds. I also tried variations on the name with different capitalization (scrolltox, ScrollToX, etc.), hoping that perhaps it was just a typo in the API docs, but I've still had no luck. :(

However, I see there is a "scrollToPosition". It positions the scroll view image at x,y, around the top-left corner of the screen, not the center of the screen.

So, to scroll to the center of your image, do it this way:

1
2
3
4
5
6
7
8
local screenW, screenH = display.contentWidth, display.contentHeight
local midscreenX = screenW*(0.5) 
local midscreenY = screenH*(0.5) 
...
 -- show at center immediately.
local timeToScroll = 0
 
myscrollview:scrollToPosition(-myscrollview.contentWidth/2 + midscreenX,-myscrollview.contentHeight/2 + midscreenY,timeToScroll)

That's great! I hadn't thought to use the scrollToPosition method instead. Thanks!

The absence of the scrollToX method is still a bug, but your suggestion helps me out a great deal. Thanks!

ARGH! I can't get the scrollView object to insert into something else and behave! It is sitting on top of everything!

Using daily build #732, I'm able to insert scrollViews into display groups using this syntax:

1
2
3
4
5
someGroup = display.newGroup()
 
scrollView = widget.newScrollView{[parameters]}
 
someGroup:insert(scrollView)

My silly bad...a local in a block...it works.

Hey guys - have you filed a bug report with sample code?

Danny was investigating this on another thread a few days ago, no reply since though.

http://developer.anscamobile.com/forum/2012/01/11/build-723-missing-methods-newscrollview

@Peach: Yes, I filed a bug shortly after I started this thread. The case # is 11784. Thanks!

Hi everyone. There is a mismatch in the documentation. scrollToX and scrollToY are internal methods that are not publicly available. Instead, you use scrollToPosition (no need to wait for a daily build, it's already in there).

Here's the syntax:

scrollView:scrollToPosition( [x, y, timeInMs, onComplete] )

Thanks, Jonathan!

views:2845 update:2012/2/10 9:26:24
corona forums © 2003-2011