Hello there Corona Forum people. 1st post so go easy on me
I’m sure it’s been asked many times already and I have searched the forums and internet as a whole for a solution but as yet have not found one.
I have a storyboard with several scenes on, one in particular loaded a remote image [loadRemoteImage] when I click on that scene.
I had issues whereby if another one of the scenes was clicked the image would still show on that scene. I tried all manner of ways to try and remove it from memory etc but could not find a way. In the end I opted for io.open and then displayed that image via display.newImageRect
This seems to now remove okay when I click on one of the other scenes. 1st issues sorted, maybe!
2nd issue is to now have a way of re-loading the image if I go back into that scene. I’m pretty sure I need to remove, purge, nil that image somehow but cannot for the life of me figure it out. Here is the code for that scene and if you can point me in the right direction I’d be eternally grateful.
I just need to get know how to remove, purge the image when I exit that scene so it reloads correctly on going back into that scene. Thank you. Here’s the code
[lua]
–[[ $Id$
–]]
– Load the relevant LuaSocket modules
local http = require(“socket.http”)
local ltn12 = require(“ltn12”)
local bsc = require “xxxxxx.interface.bsc”
local ui = require “xxxxxx.interface.ui”
local storyboard = require “storyboard”
local scene = storyboard.newScene()
– Create local file for saving data
local path = system.pathForFile( “snapshot.jpg”, system.DocumentsDirectory )
myFile = io.open( path, “w+b” )
– forward declarations
local object1
–createScene
function scene:createScene( event )
local group = self.view
– Request remote file and save data to local file
http.request{
url = “http://xxx.xxx.xxx.xxx/xxx/snapshot.jpg”,
sink = ltn12.sink.file(myFile),
}
object1 = display.newImageRect( “snapshot.jpg”,system.DocumentsDirectory, 300, 230 )
object1:setReferencePoint( display.CenterReferencePoint )
object1.x = display.contentCenterX
object1.y = display.contentCenterY
group:insert( object1 )
end
scene:addEventListener( “createScene”, scene )
–enterScene
function scene:enterScene( event )
local group = self.view
object1.isVisible = true
end
scene:addEventListener( “enterScene”, scene )
–exitScene
function scene:exitScene( event )
local group = self.view
end
scene:addEventListener( “exitScene”, scene )
–destroyScene
function scene:destroyScene( event )
local group = self.view
end
scene:addEventListener( “destroyScene”, scene )
return scene
[/lua]