New to Corona SDK and LUA, question of assigning variable of RemoteLoadImage and remove it after Sense

Hi everyone, I got told from my company to create an application for them, and I never learn anything about Corona SDK.

Here is my code for a sense, but after I display the image, I have no idea how to remove it when I go back to the the previous.

----------------------------------------------------------------------------------------- -- -- scene2.1.lua -- Nov 18, 2015 -- created by Isaac LI ----------------------------------------------------------------------------------------- local composer = require( "composer" ) local scene = composer.newScene() -- ----------------------------------------------------------------------------------------------------------------- -- All code outside of the listener functions will only be executed ONCE unless "composer.removeScene()" is called. -- ----------------------------------------------------------------------------------------------------------------- -- local forward references should go here local widget = require( "widget" ) local http = require("socket.http") local ltn12 = require("ltn12") local path local myFile --------------------------------------------------------------------------- local BackButtonPress = function( event ) composer.gotoScene( "scene2" ) end --------------------------------------------------------------------------- function showImage() native.setActivityIndicator (false) testImage = display.newImage("jg.png", system.DocumentsDirectory,display.contentCenterX,400); end --------------------------------------------------------------------------- function loadImage1() -- Create local file for saving data path = system.pathForFile( "Police\_car.png", system.DocumentsDirectory ) myFile = io.open( path, "w+b" ) native.setActivityIndicator( true ) -- show busy -- Request remote file and save data to local file http.request{ url = "http://www.odyy.org/jg.png", sink = ltn12.sink.file(myFile), } -- Call the showImage function after a short time dealy timer.performWithDelay( 1, showImage) end --------------------------------------------------------------------------------- -- "scene:create()" function scene:create( event ) local sceneGroup = self.view local CH\_Sidebutton = widget.newButton { id= "Side", defaultFile = "images/buttonGreen.png", overFile = "images/buttonGreenOver.png", label = "New Images", font = native.systemFont, fontSize = 22, width = 100, height = 60, onEvent = loadImage1 } CH\_Sidebutton.x=160 CH\_Sidebutton.y=800 local BackButton = widget.newButton { id= "back", defaultFile = "images/BackButton.png", overFile = "images/BackButton.png", font = native.systemFont, fontSize = 22, width = 100, height = 60, onEvent = BackButtonPress } BackButton.x=60 BackButton.y=1200 -------------------------------------------------------------------------------------- sceneGroup:insert(BackButton) sceneGroup:insert(CH\_Sidebutton) -------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- -- -- setup a page background, really not that important though composer -- crashes out if there isn't a display object in the view. -- end function scene:show( event ) local sceneGroup = self.view params = event.params utility.print\_r(event) end -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. -- "scene:show()" function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). -- These are the functions triggered by the buttons elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view end -- ------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ------------------------------------------------------------------------------- return scene

Please only ask your question once. Also when posting code, please use the blue <> button in the bar with bold and italics and paste your code in the box that pops up.

Please only ask your question once. Also when posting code, please use the blue <> button in the bar with bold and italics and paste your code in the box that pops up.