Quantcast WoWInterface - View Single Post - Remove a Frame element with LUA
View Single Post
11-25-09, 12:01 PM   #17
nightcracker
A Molten Giant
 
nightcracker's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 716
I see, but still I think you should clean up the frame a little bit more, since once you'd want to reuse a frame you get all the rubbish hooked to it. What about this? I'm planning to release it as a lib.
LUA Code:
  1. FrameHandler = {
  2.     cache = {},
  3.     scripts = {
  4.         OnDragStart = true,
  5.         OnDragStop = true,
  6.         OnEnter = true,
  7.         OnEvent = true,
  8.         OnKeyDown = true,
  9.         OnKeyUp = true,
  10.         OnLeave = true,
  11.         OnLoad = true,
  12.         OnMouseDown = true,
  13.         OnMouseUp = true,
  14.         OnMouseWheel = true,
  15.         OnReceiveDrag = true,
  16.         OnSizeChanged = true,
  17.         OnUpdate = true,
  18.     },
  19. }
  20.  
  21. function FrameHandler:CreateFrame(parent, name, inherits)
  22.     local parent = parent or UIParent
  23.     local f = tremove(FrameHandler.cache) or CreateFrame("Frame")
  24.     if name or inherits then
  25.         local f = CreateFrame("Frame", name, parent, inherits)
  26.     else
  27.         local f = tremove(FrameHandler.cache) or CreateFrame("Frame")
  28.     end
  29.     f:SetParent(parent)
  30.     f:Show()
  31.     return f
  32. end
  33.  
  34. function FrameHandler:DeleteFrame(f)
  35.     local name = f:GetName()
  36.     f:Hide()
  37.     f:SetParent(nil)
  38.     f:UnregisterAllEvents()
  39.     f:SetID(0)
  40.     f:ClearAllPoints()
  41.     for script, _ in pairs(FrameHandler.scripts) do
  42.         f:SetScript(script, nil)
  43.     end
  44.     if name then
  45.         _G[name] = nil
  46.     end
  47.     tinsert(FrameHandler.cache, f)
  48. end
__________________
Three things are certain,
Death, taxes and site not found,
You, victim of one.
  Reply With Quote