For the project that I am working on, I need to download a some images and insert those image to the different display group. Each image should have a ID so I can keep tracking them.
But looks like network.download can not pass a value to the networkListener except filename and directory.
What I did is name the downloaded files by the ID, and then use the file name to track them.
But I’m sure there should be a better way to do it.
I heard Rob said some thing about “anonymous functions and closures” cloud helps, but I have no idea how it should works
http://coronalabs.com/blog/2014/02/18/tutorial-anonymous-functions-and-closures/
I ready those topic but there isn’t a sample code, could any1 plz give me some idea / hit how this code should looks like?
Thanks a lot.
local function networkListener(event) if ( event.phase == "ended" ) then local fn = event.response.filename local ID = tonumber(fn:sub(1,1)) NImage[ID] = display.newImageRect(event.response.filename, event.response.baseDirectory,320,320) NIGroup[ID]:insert(NImage[ID]) end end NIGroup = {} NImage = {} for i = 1, 5 do NIGroup[i] = display.newGroup() network.download("http:xxxxxx/test"..i..".png", "GET",networkListener,i..".png",system.TemporaryDirectory) end