You are absolutely right, i’m using storyboard as first lua script and the second is self contained module.
First lusa script has this code:
local function country_obj(country_image,country_mask,json_name)
local this_country = display.newImage(country_image)
this_country.jsonname = json_name
placeCountry(this_country)
local masked_country = graphics.newMask( country_mask )
this_country:setMask( masked_country )
local function onTouch(event)
if “ended” == event.phase then
jsonRequester : GetInfo(nil,“mapinfo.php”,“mapinfo”,“country_index”,event.target.jsonname,nil,nil,nil,nil);
end
end
this_country:addEventListener(“touch”,onTouch)
return this_country
end
and second script contain:
local jsonFile = function( filename, base,my_var )
– set default base dir if none specified
if not base then base = system.ResourceDirectory; end
– create a file path for corona i/o
local path = system.pathForFile( filename, base );
– will hold contents of file
local contents
– io.open opens a file at path. returns nil if no file found
local file = io.open( path, “r” ) ;
if file then
– read all contents of file into a string
contents = file:read( “*a” ) ;
io.close( file ); – close the file after using it
end
return contents ;
end
local function getmapinfo( event)
if ( event.isError ) then
storyboard.errno = 1;
storyboard.gotoScene( “maintaince” )
return true
else
print ( "RESPONSE: " … event.response );
local t = json.decode( event.response );
– Go through the array in a loop
for key in pairs(t) do
– Here you can do whatever you like with the values
– print(t[key][“index”]);
– print(t[key][“country_name_eng”]);
end
return event.responce
end
end
function jsonRequester : getInfo (url,script,auth_param,param1,param1_val,param2,param2_val,param3,param3_val)
local json_file_by_get
json_file_by_get = jsonFile( network.request( “https://”…serverip…"/"…script…"?auth="…auth_param…"&"…param1…"="…param1_val, “GET”, getmapinfo));
end
end