Need help toggling an image

I’m using a button to display an image and I want to use the same button to get rid of the image. Displaying the image is working great but I’m having trouble getting rid of the image.

Any help/suggestions greatly appreciated.

[code]
local function onMasterImage( event )
print(“in onMasterImage”)
if imageup == false then
print(“in onMasterImage imageup=false”)
local myImage2 = {}
local function networkListener2( event )
if ( event.isError ) then
print ( “Network error - download failed” )
else
event.target.alpha = 0
transition.to( event.target, { alpha = 1.0 } )
end
myImage2 = event.target
print ( "RESPONSE: " … event.response )
end

display.loadRemoteImage(
http://shop.rareparts.com/img/img300/” … “10100” … “.jpg”,
“GET”,
networkListener2,
“helloCopy2.png”,
system.TemporaryDirectory,
10, 180 )
imageup = true
else
– need to get rid if image here
print(“in onMasterImage imageup=true”)

—> code needed to get rid of the image displayed

imageup = false
end
end

[/code] [import]uid: 6547 topic_id: 21680 reply_id: 321680[/import]

Have you tried event.target:removeSelf() within your else statement? [import]uid: 80890 topic_id: 21680 reply_id: 85994[/import]

Yes, but must be in wrong place. Makes Corona puke.
I must have the if-then-else wrong.

else -- need to get rid if image here print("in onMasterImage imageup=true") imageup = false event.target:removeSelf() end [import]uid: 6547 topic_id: 21680 reply_id: 85997[/import]

This may not be the most efficient, but it works as needed. Thanks for the hint weberkeith.

[code]

local function onMasterImage( event )
print(“in onMasterImage”)
if imageup == false then
print(“in onMasterImage imageup=false”)
myImage2 = {}
function networkListener2( event )
if ( event.isError ) then
print ( “Network error - download failed” )
else
event.target.alpha = 0
transition.to( event.target, { alpha = 1.0 } )
end
myImage2 = event.target
print ( "RESPONSE: " … event.response )
end
display.loadRemoteImage(
http://shop.rareparts.com/img/img300/” … “10100” … “.jpg”,
“GET”,
networkListener2,
“helloCopy2.png”,
system.TemporaryDirectory,
10, 180 )
imageup = true
else
– need to get rid if image here
print(“in onMasterImage imageup=true”)
imageup = false
myImage2.alpha=0
end
end
[/code] [import]uid: 6547 topic_id: 21680 reply_id: 86004[/import]