Originally Posted by Fizzlemizz
Frames don't get disposed/garbage collected. You should re-use the same frame where possible.
The global name of the first frame created with the same name is stored so you would need to keep track of any frames created yourself, most commonly by adding the reference to a table, or use unique names.
Lua Code:
local MyButtons = {} -- Storage local function CreateButton(id) local f = CreateFrame("Button", "MiltonActionButton"..id, UIParent, "SecureActionButtonTemplate") -- Create your button(s) tinsert(MyButtons, f) -- and add to storage ... end local function HideButtons() for i=1, #MyButtons do -- Hide them all MyButtons[i]:Hide() end end
|
Thank you, it worked like a charm. I added a MyButtons[i] = nil to the loop so that the table contains only the new frames created.
frame:SetParent(nil) I got from here
Never forget to unset the frames parent, if you want to get rid of a frame. I would suggest to hide the frame via frame:Hide() and to use frame:SetParent(nil) afterward (this will remove the frame from its parents child list). If you just hide the frame without this additional step, frames created afterward will get a higher framelevel than the hidden one. After a while, you will get frames at maximum framelevel which are likely to be drawn in a distorted way (false order caused by equal framelevel).
|
https://wowwiki.fandom.com/wiki/API_CreateFrame
Originally Posted by Seerah
... why though?
|
Because the location is important. I want the button(s) right in the center of the screen so I can click through them fast. And I want them to take as little of my screen as possible (and I'm a lua noob so anything more complex requires hours of research).