Async image download problem

I have a number of images loaded up by looping over an array. The only thing is that this freezes the device until all 15 images are downloaded and displayed. Async image download would be an excellent solution to this, but I can't get it to perform reliably within loop code.

Note: Images I'm downloading aren't ever over 20 KB (200x300 pixels).

Loop code:

1
2
3
for z=1,15 do
...
end

off the top of my head

you are clobbering the listener

try a different approach or once the image finishes call back again

1
2
3
4
neworklistener(...)
 ...after image is loaded ... call next image
 
end

How would you use the

1
call next image

use a counter not a for..loop

use a counter not a for..loop

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
local z = 0
local totalImages = 15
 
local done
local loadNextImage
 
local function networkListener()
 
  if(z<totalImages) then
    loadNextImage()
  else
    done()
  end  
 
end
 
function loadNextImage()
 
  z=z+1
 
  display.loadRemoteImage( 
        "http://developer.anscamobile.com/demo/hello" .. z .. ".png", 
        "GET", 
        networkListener, 
        "helloCopy-" .. z .. ".png", 
        system.TemporaryDirectory, 
        60, 280 )
  
end
 
function done()
  print("done")
end
 
loadNextImage()
views:2184 update:2011/9/17 17:36:44
corona forums © 2003-2011