widget.newScrollView

Hmm, not having much luck here - I keep crashing the simulator.

I’ve implemented my own lazy load, it basically takes a scrollView and an index as parameters, and loads the n-1,n and n+1 images. It also scans through any other child objects outside of that range and removes them.

I’ve tried scrollView:remove(index) and scrollView.content:remove(index) but nothing works.

Here is my code:

[code]
– Loads the current, previous and next images in a scroll view
function loadScrollImages(scrollView,index)

print(“ScrollView has “…scrollView.numChildren…” children”)
print(“ScrollView.content has “…scrollView.content.numChildren…” children”)

– Load new images
for i=index-1,index+1 do
if(i>0 and i local partImage = display.newImageRect(“assets/images/parts/”…scrollImages[i]…".png",320,144)
partImage:setReferencePoint(display.TopLeftReferencePoint)
scrollView.content:insert(partImage)
partImage.x = ((i-1) * partImage.width)
partImage.y = 0
end
end

– Unload old images
for i=1,scrollView.content.numChildren do
if(iindex+1) then
– What goes here???
end
end

end
[/code] [import]uid: 140429 topic_id: 24278 reply_id: 106787[/import]

If you are removing objects from a group, you need to remove them in reverse order or you will end up removing a “nil” object and your app will get a runtime error.

For example:

scrollView.content:remove( scrollView.numChildren ) 

You can verify the problem by printing the value of “i” and “scrollView.numChildren” in your Unload loop. [import]uid: 7559 topic_id: 24278 reply_id: 106820[/import]

Hi Tom,

Thanks for the update. The thing is, I need to remove objects in a different order to how they are added. The lazy-loader needs to remove any images that are not in view (or to either side of the current image)

Surely there is a way to do this by keeping a tab on what images have been added (and hence can also be removed)? [import]uid: 140429 topic_id: 24278 reply_id: 106821[/import]

I admit your code is a bit difficult for me to get my head around, but my first thought is simply that it’s really hard to assume that you can keep images in an order that makes sense to the group index.

And even if it did, as Tom said your removal process kills it because after a single delete, ‘i’ is no longer what you thought it was.

If you want to see if it will work, though, you’ll basically need to break the loop and re-run it every time you have to delete an image, because if it’s before ‘i’ you’ve killed the ‘for’ order and if it’s after you’ve killed the max value.

So something like

[code]-- Unload old images
local keepgoing = false

local function unload()
keepgoing = false
for i=1,scrollView.content.numChildren do
if(iindex+1) then
keepgoing = true
– remove image
break – stop the loop
end
end
if keepgoing then
unload()
end
end
unload()[/code]

Maybe there’s a much cleaner way of doing this, but the goal is to just break and restart the loop so long as you find images to remove.
[import]uid: 41884 topic_id: 24278 reply_id: 106846[/import]

Richard - thanks for the code example.

Perhaps I am making it overly-complex without any real need? My 3 scroll views each contain 24 images. Normal resolution are approx 50KB each, and the @2x images are about 150KB. That’s around 10MB of memory (too much?) Do I actually need to remove the other images not on screen, or to either side of the current image?

Are there any examples that use the scrollView to do something similar to what I am after? I realise that I am still a newcomer to Corona / Lua and the ‘best’ solution isn’t always obvious. [import]uid: 140429 topic_id: 24278 reply_id: 106991[/import]

Is fluid movement coming any time soon? So we’re not only limited to moving the scrollView horizontally/vertically? The movement right now feels very restrictive [import]uid: 14018 topic_id: 24278 reply_id: 107115[/import]

Not sure if I am doing this correctly, but I can’t seem to disable vertical scroll:

myScrollView.content.vertivalScrollDisabled = true  

To continue on from my other messages, my scrollViews seem really slow with the way I am adding images. Even before needing to remove anything (lazy-load system) it still seems so slow loading up each set of 3 images. Is it better to just load everything, knowing that nothing else will be added to the screen (memory)? At most, all of the images are 11MB (3 sets of 24 @2x) [import]uid: 140429 topic_id: 24278 reply_id: 107904[/import]

FourtyFourDigital: It’s possible you are making it overly complex, but complex is fine so long as it gets the job done. I wouldn’t worry about memory. My focus would be to always keep 3 images in memory per view (“Left” “Center” “Right”) and just effectively swap them, either by drag or by runtime.

I can’t think of any specific examples but I really just have not spent enough time with scrollView lately. Just, like I said, try not to rely on ‘i’ being an accurate idea of where your scrollView is in terms of image order, because it’s incredibly easy to just turn the entire order into a random one. You should always either:

a) use for loops to figure out which indexes are important, or…
b) keep a constantly updated table going with that information

If you could load images individually, that would be best. But what format are you using? (There are clear benefits to using certain types, particularly at iPad 2x) [import]uid: 41884 topic_id: 24278 reply_id: 107924[/import]

Richard, thanks for continuing to help.

As it stands, I have the 3 images in view as you say, but cannot remove the others once the positions are changed. I’ll keep trying. The images have a slight delay as they load, but until I can fix the roving part - they gradually all load into memory. From then on, it runs quite quickly.

If I load all the images in my storyboard function scene:createScene(event), then it takes a few seconds to load, but then runs well.

The images are PNG32 because I need them to have a transparent background (they all overlay onto another image). These obviously look pretty nice on all the devices, but at the cost of filesize/memory.

Alex [import]uid: 140429 topic_id: 24278 reply_id: 108044[/import]

What do you mean by “cannot remove the others once the positions are changed?” [import]uid: 41884 topic_id: 24278 reply_id: 108064[/import]

Well, if I try and do scrollView.content:remove() or scrollView:remove() - I can never seem to remove the images from the view.

I’m just trying a few things now, but not having much luck with it all [import]uid: 140429 topic_id: 24278 reply_id: 108067[/import]

Can’t you just use display.remove(object)? [import]uid: 41884 topic_id: 24278 reply_id: 108069[/import]

Is it a bug or do I make something wrong ?

I have a scrollView (with buttons in it) on a scene.
When I go out the scene, I remove the scrollView.
I go the other scene which has the same buttons list.
The only difference is the bitmap of the button.

When I build for Xcode Simulator, it works.

When i build for Device, it crashes, the console give a esoteric error with pvalue and some ?.

If I use the same bitmap for the two list of buttons, it works…

That what I did. But I do not understand why the two scrollView are “considered as the same object” despite the fact I remove then when I exit scene.

Any clue ? [import]uid: 5578 topic_id: 24278 reply_id: 110695[/import]

the property is mis-spelled. vertival instead of vertical [import]uid: 6317 topic_id: 24278 reply_id: 110730[/import]

Can you please prioritize fluid movement to the scrollView??? It feels like it’s time, being able to only move in the vertical / horizontal directions doesn’t make any sense, a scrollView is supposed to be able to move in all directions
Thanks [import]uid: 14018 topic_id: 24278 reply_id: 110963[/import]

In the ScrollView Documentation we hove some erros.
The scrollView:getScrollPosition(); isn’t working;
the scrollView:scrollToY( yPosition, timeInMs ); isn’t working too;

the only things i see working but isn’t the thing i want is
scrollView:scrollToPosition();
print(scrollView:getContentPosition());

So i need help and ask you guys from ansca updating the documentation api for the ScrollView Widget.

Ty [import]uid: 114525 topic_id: 24278 reply_id: 111522[/import]

@p.peresjr: If you’re using build 2012.721 or later, then you’ll need to refer to this documentation page for the scrollview widget instead:

http://developer.anscamobile.com/reference/index/scrollview-after-build-2011715

scrollView:scrollToY() has been replaced with scrollView:scrollToPosition().

scrollView:getScrollPosition() has been replaced with scrollView:getContentPosition().

In both cases above, the API’s were changed for clarity but the functionality remained the same. It’s likely the other two functions also didn’t do what you wanted them to do as well. Feel free to send in a feature request if specific functionality isn’t there, that you feel should be.

EDIT: We’ll be rolling out our brand new documentation soon, so these little points of documentation confusion shouldn’t happen anymore after that :slight_smile: [import]uid: 52430 topic_id: 24278 reply_id: 111566[/import]

Has anyone gotten the ScrollView widget working with Director Class? Although it works fine in the simulator, my app keeps crashing when I test it on my Droid Pro and Kindle Fire. [import]uid: 151029 topic_id: 24278 reply_id: 112263[/import]

Has anyone had any luck getting the scrollView widget working while an item inside it responds to the ‘touch’ event? I have an image inside the my scrollView that listens for a ‘touch’ event, and it needs to be able to respond to both the ‘began’ and ‘ended’ phases, but the scrollView also needs to be able to scroll, even if this image is the first thing that is touched. What I’ve determined so far is that if I return false for the ‘began’ phase the scrollView will scroll but I won’t get the ‘ended’ phase, and if i return true for the ‘began’ phase the scrollView won’t scroll, but I get the ‘ended’ phase. Is there no way I can get both the scrolling, and the ‘ended’ phase? Can I please have my cake and eat it to? [import]uid: 143007 topic_id: 24278 reply_id: 116794[/import]

sps3: Sorry, I don’t think it’s normally possible. As you say, scrollView swallows the ended phase without using return true.

The only work around you might be able to do is try firing off a custom event with an ended phase that the image is set to receive (since scrollView has its own event structure), but that’s a pretty half baked idea; I have no idea if it would work. [import]uid: 41884 topic_id: 24278 reply_id: 116800[/import]