scrollView not empty by default?!

Here I create a new scrollView:

local scroll = widget.newScrollView( { backgroundColor = { 34 /255, 49 /255, 63 /255 },         width = 400,         height = 1000,         scrollWidth = 400,         horizontalScrollDisabled = true,         leftPadding = 50,         topPadding = 5 } ) sceneGroup:insert( scroll )

Here I check for number of children in the scrollView:

print( "scroll children: "..scroll.numChildren )

Result:

3

This is messing up the way I sort objects inside that scrollView, because I was testing to see if the scroll has children yet or not and based on that I sort the objects inside it.

The scroll object is not the group that makes up the scrollView. That count isn’t the count of objects in the view. The view itself (while technically visible) is considered a private member of the object. I think its:  scroll._view or something like that. 

We don’t encourage access to private members (Lua doesn’t have a private concept) since we are subject to change them, but many people do access the ._view property.

Rob

So are there 3 objects inside the scroll object by default, or am I missing something here?!

What I want is to create objects and insert them into the scroll object.  Later I want to get the number of objects inside the scroll object, but the result I get is not accurate. 

The scrollview itself is a container with a bunch of stuff added onto it to do neat things, it contains a few things one of which is the displaygroup that holds the things you insert into it. That displaygroup moves about within the container to make the scrolling happen.

You could either do something like myScrollView._view.numChildren

Or, keep track of what you’ve put in it somewhere outside of the scrollview

Or modify the scrollview itself to work how you want it to. (the source is on github)

doing myScrollView:insert(thing) actually inserts it into myScrollView._view, works out the new size of the scroll area and then scrolls it back to where it was before you did the insert.

Got it, thanks. 

The scroll object is not the group that makes up the scrollView. That count isn’t the count of objects in the view. The view itself (while technically visible) is considered a private member of the object. I think its:  scroll._view or something like that. 

We don’t encourage access to private members (Lua doesn’t have a private concept) since we are subject to change them, but many people do access the ._view property.

Rob

So are there 3 objects inside the scroll object by default, or am I missing something here?!

What I want is to create objects and insert them into the scroll object.  Later I want to get the number of objects inside the scroll object, but the result I get is not accurate. 

The scrollview itself is a container with a bunch of stuff added onto it to do neat things, it contains a few things one of which is the displaygroup that holds the things you insert into it. That displaygroup moves about within the container to make the scrolling happen.

You could either do something like myScrollView._view.numChildren

Or, keep track of what you’ve put in it somewhere outside of the scrollview

Or modify the scrollview itself to work how you want it to. (the source is on github)

doing myScrollView:insert(thing) actually inserts it into myScrollView._view, works out the new size of the scroll area and then scrolls it back to where it was before you did the insert.

Got it, thanks.