WoWInterface - View Single Post - Closing all frames with the same name
View Single Post
04-17-20, 02:31 PM   #4
A Murloc Raider
Join Date: Apr 2020
Posts: 4
Originally Posted by Fizzlemizz View Post
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:
  1. local MyButtons = {} -- Storage
  3. local function CreateButton(id)
  4.     local f = CreateFrame("Button", "MiltonActionButton"..id, UIParent, "SecureActionButtonTemplate") -- Create your button(s)
  5.     tinsert(MyButtons, f) -- and add to storage
  6.     ...
  7. end
  9. local function HideButtons()
  10.     for i=1, #MyButtons do -- Hide them all
  11.          MyButtons[i]:Hide()
  12.     end
  13. 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).

Originally Posted by Seerah View Post
... 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).
  Reply With Quote