Closing all frames with the same name
I am creating many frames in the same spot, overlapping one another, with this:
local tar_btn = CreateFrame("Button", "get_tar", UIParent, "SecureActionButtonTemplate") when I click them, they do what I need them to do and then close, one after the other: tar_btn:SetScript("PostClick", function (self, button, down) -- if button == "RightButton" then -- ... -- end self:Hide() self:SetParent(nil) end) I want them all to close at the same time when I right click, what command can I give so all frames with the name "get_tar" disappear and get garbage collected when I right click on any one of them? This didn't work: if button == "RightButton" then get_tar:Hide() get_tar:SetParent(nil) end |
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:
|
Quote:
|
Quote:
frame:SetParent(nil) I got from here Quote:
Quote:
|
In this instance, "get rid of" doesn't mean dispose and release resources, it just means, "not see" and avoid some possible future problems with new frames.
Setting the parent to nil just releases it from the strictures of being a child of it's current parent (following scale, hide state etc.). |
Quote:
Quote:
They all behave like different frames - each one appears and disappears as needed and they can all be on the screen at the same time - so I don't know how would I be reusing the same frame instead of creating a new one (with its appropriate resources) every time. |
It depends on what you are doing with the buttons and how many you need active at the one time (if you are just stacking one on top of the other it sounds like you only need one).
An example of re-use is your action bar buttons. You can change the spell/action for a single button any number of times by dragging a spell/item etc. onto it. This doesn't create a new button each time, just changes what the current button is used for. You could use re-use individual button from the table if you identify which one is no longer in use. Cheesey example using the 3rd button created to re-use: Code:
local reUseButton = MyButtons[3] |
Ah, I understand. Reusing it means just changing the functionality of it, what is displayed and what it does, without creating a new frame.
In this case, I create maybe 500 new frames during a play session, it probably has no impact on the overall performance of the game at this level. On the other hand, there would be no more than 10 frames overlapping at any one time, so I could reduce the number to 10 and have cleaner code (or rather just one frame as you suggested earlier, though it's more difficult to implement). Maybe I will when I get a little bored with the actual game. Thank you for sharing your wisdom. |
Quote:
|
All times are GMT -6. The time now is 09:57 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI