Corona sdk call loadRemoteImage with extra params

I have a scene with a number of images loaded remotely. I call for those images on scene:show and in their listener I check if the user is still on that scene, if not, I simply remove the event.target.

My problem is that the user can enter->exit->enter the scene quick enough, so that the listener would load and show the images from the first entrance.

I would like to be able to pass an ID when I call loadRemoteImage, so that when it comes back in the listener I can check if it is still relevant.

Any ideas?

Yes. Associate the listener with the objects you want to fill.  Then, if the object is removed, the listener is ignored.

If you can’t work this out, post back and I’ll see if I have an example.

Hi @roaminggamer thanks for the reply.

Here’s my problem, I have a Scrollview that shows many items to chose from, created onCreate. I run through the table onShow and insert the proper downloaded images into it. I remove the scene completely onHide.

This is a simplified code of what I am doing. And if a user exists this scene and enters it quick enough. The images from the first entrance, after checking it’s the correct scene, will display the images downloaded from the first entrance.

-- Create the widget local scrollView = require('widget').newScrollView( { top = 100, left = 10, width = 300, height = 400, scrollWidth = 600, scrollHeight = 800, } ) local function Create\_One( \_url, \_Card\_Y ) local CARD = display.newGroup() local function Remote\_Image\_Listener( event ) local rightScene = false if(composer.getSceneName("current") == "scenes.Event\_Details")then rightScene = true end if(event.status == 200) and rightScene then event.target.anchorY = 0 event.target.anchorX = 1 event.target.width = 300 event.target.height = 200 CARD:insert( event.target ) else if(event.target)then event.target:removeSelf() end print("Remote Image Download Canceled") end end local F1\_Image = display.loadRemoteImage( \_url, "GET", Remote\_Image\_Listener, fileName, system.DocumentsDirectory, ScrollView.width/2 , Card\_Y ) return CARD end local Card\_Y = 150 for i=1,300 do Card\_Y = Card\_Y + 250 local Card = Create\_One\_Card( IMAGE\_URL, Card\_Y) ScrollView:insert( Card ) end

I would really like it if I could send more params so I could check the image relevance alongside the correct scene.

Thank you,

Mor from Mars Team

Before I try helping, I have some questions:

1 . Do you know the size/dimension of the images before you download them?

  1. You inserting these images into your scroller/page in the order you request them or are the being placed in the order the requests are returned in?  i.e. Do you decide their placement before they return or after?
  1. No, I don’t.
  2. I give the images a Y variable when they’re called, so I technically insert them before they return.

Have you considered using network.download() instead?  Then you can simply cancel all outstanding requests when you exit the scene.

I have an example of how to get images using network.download().  It also shows  how to use the downloaded image as a fill for an existing placeholder rectangle.

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2016/09/remoteFiles2.zip

Alternately, you can replace the ‘placeholder’.

You cancel outstanding requests with this function: https://docs.coronalabs.com/api/library/network/cancel.html

If this sounds like a good idea, but you get stuck on the implementation, I can make a small example as a level-1 hit, that would include these parts:

  • two scenes - so you can test switching away from the ‘waiting’ scene.
  • scroller
  • placeholders w/ dynamic adjustment to ‘fit’ the image in the scroller when it get there.
  • code to remove old images on next restart of app (would require SSK files lib).

That would be probably be enough for you to see how it works and put similar functionality into your own project.

Yes. Associate the listener with the objects you want to fill.  Then, if the object is removed, the listener is ignored.

If you can’t work this out, post back and I’ll see if I have an example.

Hi @roaminggamer thanks for the reply.

Here’s my problem, I have a Scrollview that shows many items to chose from, created onCreate. I run through the table onShow and insert the proper downloaded images into it. I remove the scene completely onHide.

This is a simplified code of what I am doing. And if a user exists this scene and enters it quick enough. The images from the first entrance, after checking it’s the correct scene, will display the images downloaded from the first entrance.

-- Create the widget local scrollView = require('widget').newScrollView( { top = 100, left = 10, width = 300, height = 400, scrollWidth = 600, scrollHeight = 800, } ) local function Create\_One( \_url, \_Card\_Y ) local CARD = display.newGroup() local function Remote\_Image\_Listener( event ) local rightScene = false if(composer.getSceneName("current") == "scenes.Event\_Details")then rightScene = true end if(event.status == 200) and rightScene then event.target.anchorY = 0 event.target.anchorX = 1 event.target.width = 300 event.target.height = 200 CARD:insert( event.target ) else if(event.target)then event.target:removeSelf() end print("Remote Image Download Canceled") end end local F1\_Image = display.loadRemoteImage( \_url, "GET", Remote\_Image\_Listener, fileName, system.DocumentsDirectory, ScrollView.width/2 , Card\_Y ) return CARD end local Card\_Y = 150 for i=1,300 do Card\_Y = Card\_Y + 250 local Card = Create\_One\_Card( IMAGE\_URL, Card\_Y) ScrollView:insert( Card ) end

I would really like it if I could send more params so I could check the image relevance alongside the correct scene.

Thank you,

Mor from Mars Team

Before I try helping, I have some questions:

1 . Do you know the size/dimension of the images before you download them?

  1. You inserting these images into your scroller/page in the order you request them or are the being placed in the order the requests are returned in?  i.e. Do you decide their placement before they return or after?
  1. No, I don’t.
  2. I give the images a Y variable when they’re called, so I technically insert them before they return.

Have you considered using network.download() instead?  Then you can simply cancel all outstanding requests when you exit the scene.

I have an example of how to get images using network.download().  It also shows  how to use the downloaded image as a fill for an existing placeholder rectangle.

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2016/09/remoteFiles2.zip

Alternately, you can replace the ‘placeholder’.

You cancel outstanding requests with this function: https://docs.coronalabs.com/api/library/network/cancel.html

If this sounds like a good idea, but you get stuck on the implementation, I can make a small example as a level-1 hit, that would include these parts:

  • two scenes - so you can test switching away from the ‘waiting’ scene.
  • scroller
  • placeholders w/ dynamic adjustment to ‘fit’ the image in the scroller when it get there.
  • code to remove old images on next restart of app (would require SSK files lib).

That would be probably be enough for you to see how it works and put similar functionality into your own project.