Hey all!
I’ve got the sample working for loading *1* single image, statically named “hello.png” found here:
http://developer.anscamobile.com/content/simple-image-download
Problem is, I have a table containing all my image locations out on the web server.
How do I load multiple images? Like, how do I get around the statically naming of files? Is there a way to pass a variable to the LoadRemoteImage function that will tell it to look for a particular filename? THATS my problem. Since it’s expecting an event, I don’t know how to proceed.
Here’s my code (which presently only downloads the first image file returned to my table from my web service, see the comments in code)
--
-- Project: LevelDownloadTest
-- Description:
--
-- Version: 1.0
-- Managed with http://CoronaProjectManager.com
--
-- Copyright 2011 Mario Roberti. All Rights Reserved.
--
remoteDirectory = "http://www.iswdev.com/stuff/battlemaps/mapthumbs/"
gameBoard = display.newGroup()
function split(pString, pPattern)
local Table = {} -- NOTE: use {n = 0} in Lua-5.0
local fpat = "(.-)" .. pPattern
local last\_end = 1
local s, e, cap = pString:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(Table,cap)
end
last\_end = e+1
s, e, cap = pString:find(fpat, last\_end)
end
if last\_end \<= #pString then
cap = pString:sub(last\_end)
table.insert(Table, cap)
end
return Table
end
local function LoadRemoteImage( event )
if ( event.isError ) then
print ( "Network error - download failed" )
else
local tempImage = display.newImage( "helloCopy.png", system.TemporaryDirectory)
tempImage.alpha = 0
gameBoard:insert(tempImage)
transition.to( tempImage, { alpha = 1.0 } )
gameBoard:insert(tempImage,false)
tempImage:toBack()
tempImage.x = math.random(100,400)
tempImage.y = math.random(100,400)
end
print ( "RESPONSE: " .. event.response )
loadSuccessful = true
end
function LoadRemoteText( event )
-- OK so my PHP script returnsa CSV string.
-- We'll parse that into a table using the
-- above 'split' function. No problem!
-- list=split(string\_to\_split,pattern\_to\_match)
-- e.g.:
list=split(event.response,",")
-- OK the table 'list' contains
-- my file names.
-- Gives us:
-- traderstop3thumb.jpg
-- withoutpitthumb.jpg
-- mineentrancethumb.jpg
-- dreestonsurroundsthumb.jpg
-- stormwatchinnthumb.jpg
for i=1,#list do
print("list["..i.."] "..list[i])
local tempFile = remoteDirectory..list[i] -- Concatenate my directory and my filename
-- Do the call to load the
network.download(tempFile, "GET", LoadRemoteImage, "helloCopy.png", system.TemporaryDirectory )
end
end
network.request( remoteDirectory.."enumerateImages.php", "GET", LoadRemoteText )
I certainly appreciate any help!! (And here I thought the PHP stuff would be the HARD part!
)
Best,
Mario [import]uid: 11636 topic_id: 15724 reply_id: 315724[/import]
[import]uid: 3826 topic_id: 15724 reply_id: 58118[/import]