From time to time in my application an image loaded by loadRemoteImage is shown on top of everything else and travels from scene to scene though it supposed to be inserted into another object as paint, etc.
I will explain what steps I did to prevent such a situation, but may be it is not enough, also I need advice from the developers of the framework as they know better how it works.
To prevent such a situation with an image in the listener sub (first) and in a few other places I put a scene name check…
local tmp_str_a = composer.getSceneName("current")
if tmp_str_a ~= "scenes.MYSCENE" then
display.remove(event.target)
-- or display.remove(obj) -- depending on the place in the code
return
end
Second, In “ended” phase I pcall a function that inserts a freshly-downloaded image into a circle. Here is a code that creates a circle, adds an image and shows the circle in a 1/4sec. (Scene-name checks are presented there, too)
local a_circle = display.newCircle(event.target.x, event.target.y, user_pic_WH_int/2)
local paint = {
type = "image",
filename = event.response.filename,
baseDir = system.ApplicationSupportDirectory
}
-- Fill the circle
a_circle.fill = paint
local tmp_bool_a = true
tmp_bool_a = pcall(sv_insert_sub, a_circle)
if tmp_bool_a == false then
display.remove(a_circle)
display.remove(event.target)
return
end
event.target.alpha = 0
transition.to(
a_circle,
{time = loading_speed_int,
alpha = 1.0}
)
local function sv_insert_sub(obj)
SV:insert(obj) -- scrollView
end
So, what am I missing here? What is the behavior of the listener-function if a scene got changed before the image was loaded. Should I block a user to change a scene if “began” phase is in progress? But what if it takes too long?
Or simply explain how to remove that internal image that I cannot get rid of