Remove RemoteImage from display

How do I remove from the display a picture which is downloaded using the following snippet (from Coronas examples):

display.loadRemoteImage( "http://www.coronalabs.com/demo/hello.png", “GET”, networkListener, “helloCopy.png”, system.TemporaryDirectory, 50, 50 )

To remove a display object use removeSelf() http://docs.coronalabs.com/daily/api/type/DisplayObject/removeSelf.html

[lua]local someImage = display.loadRemoteImage( "http://www.coronalabs.com/demo/hello.png, “GET”, networkListener, “helloCopy.png”,system.TemporaryDirectory, 50, 50 )

someImage:removeSelf()

someImage = nil

[/lua]

Thanks Jedi. I tried this yesterday, but didn’t have much success. Maybe because I displayed the pic at startup and tried to remove it inside a tap event (I’m a newbie to LUA, so I often get a little confused). I am not “rock steady” when it comes to local variables and global ones.

I will try your suggestion tonight and report back then.

Sorry, my example is no good. I have never used display.loadRemoteImage and it seems it does not return anything.

You can do something like this instead:

[lua]local function imageTap(event)

    local image = event.target

    image:removeSelf()

    image = nil

end

local function networkListener( event )

    if ( event.isError ) then

        print ( “Network error - download failed” )

    else

        local image = event.target

        image:addEventListener( “tap”, imageTap )

    end

end

display.loadRemoteImage( “https://pbs.twimg.com/profile_images/378800000366520881/02d070af6c3001a0f9d4c05b860b51eb_normal.png”, “GET”, networkListener, “helloCopy.png”,system.TemporaryDirectory, 50, 50 ) [/lua]

Your code seems to work, Jedi.When tapping the image it disappears. But in my app the image shal be removed when I tap another button.

I tried to replace the imageTap identifier with my own handleButtonEvent identifier and moved the removeSelf stuff inside this event. The result being that the button disappeared and the image remained.

I am a little stuck.

Edit: With some tweaking I made it work. Thanks Jedi!

To remove a display object use removeSelf() http://docs.coronalabs.com/daily/api/type/DisplayObject/removeSelf.html

[lua]local someImage = display.loadRemoteImage( "http://www.coronalabs.com/demo/hello.png, “GET”, networkListener, “helloCopy.png”,system.TemporaryDirectory, 50, 50 )

someImage:removeSelf()

someImage = nil

[/lua]

Thanks Jedi. I tried this yesterday, but didn’t have much success. Maybe because I displayed the pic at startup and tried to remove it inside a tap event (I’m a newbie to LUA, so I often get a little confused). I am not “rock steady” when it comes to local variables and global ones.

I will try your suggestion tonight and report back then.

Sorry, my example is no good. I have never used display.loadRemoteImage and it seems it does not return anything.

You can do something like this instead:

[lua]local function imageTap(event)

    local image = event.target

    image:removeSelf()

    image = nil

end

local function networkListener( event )

    if ( event.isError ) then

        print ( “Network error - download failed” )

    else

        local image = event.target

        image:addEventListener( “tap”, imageTap )

    end

end

display.loadRemoteImage( “https://pbs.twimg.com/profile_images/378800000366520881/02d070af6c3001a0f9d4c05b860b51eb_normal.png”, “GET”, networkListener, “helloCopy.png”,system.TemporaryDirectory, 50, 50 ) [/lua]

Your code seems to work, Jedi.When tapping the image it disappears. But in my app the image shal be removed when I tap another button.

I tried to replace the imageTap identifier with my own handleButtonEvent identifier and moved the removeSelf stuff inside this event. The result being that the button disappeared and the image remained.

I am a little stuck.

Edit: With some tweaking I made it work. Thanks Jedi!