Scrollview Widget Question

Hey everyone, this is my first post here and I am having an issue with the scrollView widget…

I am using this scrollView widget:

local scrollView = widget.newScrollView{ left = 0, top = 0, width = display.contentWidth, height = display.contentHeight, horizontalScrollDisabled = true, verticalScrollDisabled = false, }

Next, I have a lot of text objects inside the scrollView:

local textString = "Just place a bunch of text here..." local textObject = display.newText(textString,0,0,native.systemFont,14) textObject:setTextColor(0) scrollView:insert(textObject)

Now, I tried creating an anchor (functionality similar to html #) to scroll back up inside the scrollView

local function anchorTop() print("clicked anchor") --tap listener working scrollView.anchorY=0 --doesn't work end local gotoTop = display.newText("Back to Top",0,0,native.systemFont,14) gotoTop:addEventListener("tap",anchorTop)

I have tried a bunch of things, does anyone have an idea?

First of all .anchorY is a Graphics 2.0 property only available to Pro and Enterprise subscribers in the G2.0 daily builds.  All you’re doing is creating a property in your scrollview called anchorY.  

But even if you had Graphics 2.0 (and forgive me if you do, your label says Starter, so I’m going on that assumption), that’s now how Anchor points work.  It would just make your scrollView’s overlay Y be based on 0 being the top of the scrollView.

What you need to do is to store the current Y position of the scrollView when you insert that anchor text using the getContentPosition() method (see: http://docs.coronalabs.com/api/type/ScrollViewWidget/getContentPosition.html)

Then when when you tap your anchor text to go to your anchor you would then use the scrollToPosition() method (see: http://docs.coronalabs.com/api/type/ScrollViewWidget/scrollToPosition.html) to jump there.

If you only want to scroll back to the top, you could just use the scrollTo() method (see: http://docs.coronalabs.com/api/type/ScrollViewWidget/scrollTo.html)

Rob! You truly are a miracle! Thank you so much , it worked perfectly!!!

I never knew about these docs:
http://docs.coronalabs.com/api/type/

I thought this was the only info in regards to objects:

http://docs.coronalabs.com/api/library/widget/newScrollView.html

First of all .anchorY is a Graphics 2.0 property only available to Pro and Enterprise subscribers in the G2.0 daily builds.  All you’re doing is creating a property in your scrollview called anchorY.  

But even if you had Graphics 2.0 (and forgive me if you do, your label says Starter, so I’m going on that assumption), that’s now how Anchor points work.  It would just make your scrollView’s overlay Y be based on 0 being the top of the scrollView.

What you need to do is to store the current Y position of the scrollView when you insert that anchor text using the getContentPosition() method (see: http://docs.coronalabs.com/api/type/ScrollViewWidget/getContentPosition.html)

Then when when you tap your anchor text to go to your anchor you would then use the scrollToPosition() method (see: http://docs.coronalabs.com/api/type/ScrollViewWidget/scrollToPosition.html) to jump there.

If you only want to scroll back to the top, you could just use the scrollTo() method (see: http://docs.coronalabs.com/api/type/ScrollViewWidget/scrollTo.html)

Rob! You truly are a miracle! Thank you so much , it worked perfectly!!!

I never knew about these docs:
http://docs.coronalabs.com/api/type/

I thought this was the only info in regards to objects:

http://docs.coronalabs.com/api/library/widget/newScrollView.html