[Resolved] display.loadRemoteImage() returns a nil object

According to API, the loadRemoteImage() function should return a table value (=object).
After execution of this code, I receive:
image1 = nil.
local function networkListenerIm( event )
if ( event.isError ) then
print ( “Network error - download failed” )
else
event.target.alpha = 0
transition.to( event.target, { alpha = 1.0 } )
end

print ( "RESPONSE: " … event.response )

end

local function onRowRender( event )
local group = event.view
local row = event.target
print ("event.index = "…event.index)
print("data = "…data[event.index].title)
local pictureURL = “https://graph.facebook.com/10000248xxxxxxx/picture
local image1 = display.loadRemoteImage( pictureURL , “GET”, networkListenerIm, “”…event.index…“d.png”, system.DocumentsDirectory,30 , 50 )
if (image1) then
group:insert(image1)
else
print (“Sorry, the image is loaded as nil object”)
end
group:insert( text )
end
Is it Corona’s bug or does I miss something here? Thanks [import]uid: 144261 topic_id: 29190 reply_id: 329190[/import]

Running the sample code it appears this is working fine;

[lua]local function networkListener( event )
if ( event.isError ) then
print ( “Network error - download failed” )
else
myImage = display.newImage( “helloCopy.png”, system.TemporaryDirectory, 60, 40 )
myImage.alpha = 0
transition.to( myImage, { alpha = 1.0 } )
end

print ( "RESPONSE: " … event.response )
end

test = network.download( “http://developer.anscamobile.com/demo/hello.png”, “GET”, networkListener, “helloCopy.png”, system.TemporaryDirectory )

timer.performWithDelay(1000, function() print (myImage) end, 1)[/lua]

(Threw in the timer as obviously it takes a moment to load.)

If you provide plug and play code I’d be happy to take a look at that, though. [import]uid: 52491 topic_id: 29190 reply_id: 117396[/import]

The documentation clearly states that display.loadRemoteImage() DOES NOT return anything. You can only access the display object inside the call back function (networkListener) as event.target.

See this code:

local function onRowRender( event )  
 local group = event.view  
 local row = event.target  
  
 local function networkListenerIm( event )  
 if ( event.isError ) then  
 print ( "Network error - download failed" )  
 else  
 group:insert(event.target)  
 event.target.alpha = 0  
 transition.to( event.target, { alpha = 1.0 } )  
 end  
 print ( "RESPONSE: " .. event.response )  
 end  
  
 print ("event.index = "..event.index)  
 print("data = "..data[event.index].title)  
 local pictureURL = "https://graph.facebook.com/10000248xxxxxxx/picture"  
 display.loadRemoteImage( pictureURL , "GET", networkListenerIm, ""..event.index.."d.png", system.DocumentsDirectory,30 , 50 )  
  

The positioning of the networkListenerIm function is important, since you need access to that group variable, it needs to be a function local to the networkListnerIm function.

On a side note, you should probably be using system.CachesDirectory instead of system.DocumentsDirectory as apple would likely reject the app for downloading replaceable files to the Documents directory. [import]uid: 19626 topic_id: 29190 reply_id: 117409[/import]

@peach, @robmiracle I tried two ways you proposal, and it works… Thanks a lot. [import]uid: 144261 topic_id: 29190 reply_id: 117478[/import]

Glad to hear it - marking as resolved :slight_smile: [import]uid: 52491 topic_id: 29190 reply_id: 117524[/import]