Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Corona sdk call loadRemoteImage with extra params
Started by Mars Interactive Jun 19 2018 05:30 AM

6 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Mars Interactive

[GLOBAL: userInfoPane.html]
Mars Interactive
  • Contributor

  • 167 posts
  • Corona SDK

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?



[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,119 posts
  • Corona SDK

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.



[TOPIC: post.html]
#3

Mars Interactive

[GLOBAL: userInfoPane.html]
Mars Interactive
  • Contributor

  • 167 posts
  • Corona SDK

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



[TOPIC: post.html]
#4

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,119 posts
  • Corona SDK

Before I try helping, I have some questions:

 

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

 

2. 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?



[TOPIC: post.html]
#5

Mars Interactive

[GLOBAL: userInfoPane.html]
Mars Interactive
  • Contributor

  • 167 posts
  • Corona SDK

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.

[TOPIC: post.html]
#6

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,119 posts
  • Corona SDK

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



[TOPIC: post.html]
#7

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,119 posts
  • Corona SDK

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.




[topic_controls]
[/topic_controls]