Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

display.remove won't remove display group
Started by nml2727 Jan 31 2020 07:06 PM

- - - - -
2 replies to this topic
display.remove display group close button wont close

Best Answer XeduR @Spyric , 01 February 2020 - 02:33 AM

As long as you've got those image paths and names set up properly, then that'll do it. I don't see any errors there.

 

However, I would expect you to want to actually return that "dg" to whatever file it is called from, i.e. remove "local dg" from line 3 and add "local" in front of dg on line 6.

 

Now, the question is, why do you think that the display group is still there even after you've run "closePopup"? Are you accidentally running the create function multiple times? If you are, then because you've got "local dg" outside of the function, then each additional popup will overwrite the previous one.

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

nml2727

[GLOBAL: userInfoPane.html]
nml2727
  • Enthusiast

  • 96 posts
  • Corona SDK

I have a module which creates a popup window.  It has a close button which calls display.remove on the display group.  But for some reason, the display group is still there... Code is posted below.  Can't figure out what's wrong...

local M = {}

local dg

function M.create()
	dg = display.newGroup()
	dg.x, dg.y = display.contentCenterX, display.contentCenterY

	local function closePopup(event)
		if(event.phase == "began") then

		elseif(event.phase == "ended") then
			print("Close popup!")
			display.remove(dg)
			dg = nil
		end
		return true
	end
	
	local backdrop = display.newImageRect(dg, "sprites/you_won_backdrop.png", 700,1000)
	
	local close_button = display.newImageRect(dg, "sprites/red_arrow.png", 25,25)
	close_button:addEventListener("touch", closePopup)
	
end

return M


[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,255 posts
  • Corona SDK

  Best Answer

As long as you've got those image paths and names set up properly, then that'll do it. I don't see any errors there.

 

However, I would expect you to want to actually return that "dg" to whatever file it is called from, i.e. remove "local dg" from line 3 and add "local" in front of dg on line 6.

 

Now, the question is, why do you think that the display group is still there even after you've run "closePopup"? Are you accidentally running the create function multiple times? If you are, then because you've got "local dg" outside of the function, then each additional popup will overwrite the previous one.


  • pixec likes this

[TOPIC: post.html]
#3

nml2727

[GLOBAL: userInfoPane.html]
nml2727
  • Enthusiast

  • 96 posts
  • Corona SDK

That was it!  I added a print statement to the top of the function and sure enough, it was accidentally being created multiple times from the other module. 

 

Thanks Xedur@Spyric    for thinking of that!




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: display.remove, display group, close button, wont close