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:

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

Depending at which point in my code I call the scrollToX method, the app either crashes in the simulator, or at the very least, it throws up the error message in the terminal, and the scrollView doesn’t scroll to the specified point. Below is the code I’m using to create the scrollView, and call the method. Hopefully this is just me doing something wrong, but I have a suspicion there might be a bug in the latest few daily builds. Thanks for your help!

[code]
drawerScroll = widget.newScrollView{
hideBackground=true,
left=225,
maskFile=“drawerMask.png”,
}
drawerGroup:insert(drawerScroll)

drawerScroll:scrollToX(-200) – this is the line that causes the terminal error message. If I remove it, the scrollView works just fine, but I’d really like to get the scrollToX method working!
[/code] [import]uid: 27636 topic_id: 20972 reply_id: 320972[/import]

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. [import]uid: 100222 topic_id: 20972 reply_id: 83792[/import]

It appears the method is not implemented???

“attempt to call method ‘scrollToX’ (a nil value)” [import]uid: 37366 topic_id: 20972 reply_id: 83833[/import]

@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. :frowning: [import]uid: 27636 topic_id: 20972 reply_id: 83835[/import]

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:

[code]
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)
[/code] [import]uid: 37366 topic_id: 20972 reply_id: 83836[/import]

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! [import]uid: 27636 topic_id: 20972 reply_id: 83842[/import]

ARGH! I can’t get the scrollView object to insert into something else and behave! It is sitting on top of everything! [import]uid: 37366 topic_id: 20972 reply_id: 83845[/import]

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

someGroup = display.newGroup()  
  
scrollView = widget.newScrollView{[parameters]}  
  
someGroup:insert(scrollView)  
  

Is that not working for you?
[import]uid: 27636 topic_id: 20972 reply_id: 83851[/import]

My silly bad…a local in a block…it works. [import]uid: 37366 topic_id: 20972 reply_id: 83879[/import]

Hey guys - have you filed a bug report with sample code? [import]uid: 52491 topic_id: 20972 reply_id: 83957[/import]

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 [import]uid: 100222 topic_id: 20972 reply_id: 83960[/import]

@Peach: Yes, I filed a bug shortly after I started this thread. The case # is 11784. Thanks! [import]uid: 27636 topic_id: 20972 reply_id: 84001[/import]

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] )[/code]All arguments are optional. If you want to scroll only in the X-direction, you can set y to equal the current y-value of the scrollView, or just set it to nil (and vice-versa for y-direction scrolling). You can also scroll both directions simultaneously.I'm updating the documentation right now to remove the scrollToX and scrollToY methdods and replace them with scrollToPosition. [import]uid: 52430 topic_id: 20972 reply_id: 84482[/import]

Thanks, Jonathan! [import]uid: 27636 topic_id: 20972 reply_id: 84483[/import]

I’m having trouble getting my horizontal scrolling menu to correctly stay at its current X coordinate.

Right now when the user selects a level from the scrolling menu and then comes back after they finish the level the menu is back to the first slide.

How do I get it to mark the current position of the X value of the scrollView and then go to that X value when returning to the menu?

Also wanted to note that I’m using Director Class to change scenes. [import]uid: 79620 topic_id: 20972 reply_id: 91177[/import]