Cancel Remote Load using display.loadRemoteImage()

I didn’t entirely understand how the loading of a remote image is cancelled in the docs. (Link)

Could someone elaborate or share an example?

  1. I don’t think the cancel example is correct/complete (in the docs page you linked in your post).

  2. You really should not use loadRemoteImage() if you will need to cancel the display action.

Instead, make your own code to:
a. (Optionally) create a placeholder image.
b. Download the image file. (I wouldn’t bother canceling the download unless you have a space restriction).
c. When download completes fill the object from step a or create a display object.

Then, layer on the ability to skip step c if the scene has changed and/or you no longer need to display the image.

I know this sounds like it would be hard, but it can be done easily in a self-contained function that you can then just call as needed.

Try to work this out in a standalone example and if you can’t post back that you’re stuck.

I’d be happy to make an example for you, but only after you give this a try first.

1 Like

I had a few minutes before an errand so I made:

  1. A starter module for you to expand on.
  2. Three examples using the module.

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2020/09/downloadAndDisplayImagesWithCancel.zip

The Module remoteImageHelper.lua (found in zip file)

The Examples

  • basic - Basic usage of module all in main.lua, demonstrates failed download in addition to success.
  • composer1 - Same example embedded in a composer framework. Only file of interest: scenes.playGUI.lua
  • composer2_cancel - Same file is of interest. Only change. Play gui goes back to menu as soon as ‘did’ phase of show() completes and this causes you to have to ‘cancel’ the display part of the download and display action.

I don’t expect this code to exactly match your needs, but you should be able to easily tweak it to do what you need and want.

1 Like

Don’t be confused by the way my composer scenes are made. I don’t use the traditional layout.

Why? Because I wanted to the sequential order of function calls to match the older scene library we had so (back when) folks transitioned to composer it made more sense to them.

If you look at the very bottom of a scene file, you’ll see that a semi-clever piece of code that splits show() and hide() calls into willShow(), didShow(), willHide(), and didHide(). This way I can easily keep code separated and avoid mistakes in a combined show(), hide() function.

---------------------------------------------------------------------------------
-- Scene Dispatch Events, Etc. - Generally Do Not Touch Below This Line
---------------------------------------------------------------------------------
function scene:show( event )
	local sceneGroup 	= self.view
	local willDid 	= event.phase
	if( willDid == "will" ) then
		self:willShow( event )
	elseif( willDid == "did" ) then
		self:didShow( event )
	end
end
function scene:hide( event )
	local sceneGroup 	= self.view
	local willDid 	= event.phase
	if( willDid == "will" ) then
		self:willHide( event )
	elseif( willDid == "did" ) then
		self:didHide( event )
	end
end
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
---------------------------------------------------------------------------------
return scene
1 Like