I want to download image from my server randomly
But, i find error when I want to use the image as following codes
I guess it is because the download process has not finished when I wan to use the image. therefore, error will be shown…
I would like to ask, how can i modify the code so that i can use the image after the it is downloaded?
[lua]local function networkListener( event )
if ( event.isError ) then
print( “Network error - download failed” )
elseif ( event.phase == “began” ) then
print( “Progress Phase: began” )
elseif ( event.phase == “ended” ) then
print( “displaying response image file” )
myImage = display.newImage( event.response.filename, event.response.baseDirectory, 60, 40 )
myImage.alpha = 0
transition.to( myImage, { alpha = 1.0 } )
end
end
local params = {}
params.progress = true
network.download(
“http://54.254.168.98/image/”…math.random(1,5)…".png",
“GET”,
networkListener,
params,
“helloCopy.png”,
system.TemporaryDirectory
)
[/lua]
[lua]local photo =display.newImageRect(“ball.png”,320,480)
photo.x = display.contentWidth/2
photo.y = display.contentHeight/2
photo.height= 340
photo.width= 230
[/lua]