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?
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?
I don’t think the cancel example is correct/complete (in the docs page you linked in your post).
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.
I had a few minutes before an errand so I made:
The Module remoteImageHelper.lua (found in zip file)
The Examples
scenes.playGUI.lua
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.
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