Thread Tools Display Modes
02-23-11, 08:14 PM   #1
BlueSixty
A Murloc Raider
 
BlueSixty's Avatar
Join Date: Feb 2011
Posts: 6
Destroying hiding a frame

Hi, just started learning how to write an addon for WOW and I have a question about frames.

I have setup a keybinding for my addon. I've assigned F1 to the key. When I press F1 a function in my lua will be called, showbar().

In the showbar() function I create a frame and create some other frames in it. I want one of the internal frames to allow you to click and the frame will disappear.

I have everything working but I'm not sure how to make the frame disappear. Do I just hide it? Is there some way to destroy it?

Thanks for the help

Bluesixty
  Reply With Quote
02-23-11, 09:13 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
You cannot destroy frames. You will need to hide it and then reuse/recycle the same frame the next time you want to show it (instead of creating a new one each time, which is poor coding practice).
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
02-24-11, 12:04 AM   #3
BlueSixty
A Murloc Raider
 
BlueSixty's Avatar
Join Date: Feb 2011
Posts: 6
Ah I see. that makes sense. thanks

Is there a simple way to determine if a frame exists? Or should I just maintain my own flag to know if I created it already?
  Reply With Quote
02-24-11, 02:03 AM   #4
Akkorian
A Flamescale Wyrmkin
 
Akkorian's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 111
Hi Bluesixty,

If the frame has a global name, you can look for that:

Code:
CreateFrame( "Frame", "MyGlobalFrame", UIParent )

if MyGlobalFrame then
     print( "Frame exists!" )
end
But, if you only need the frame inside your own code, and don’t need it to be accessible from outside, it’s better not to add it to the global namespace. Something like this would be a good solution:

Code:
local frame
local function InitializeFrame()
     if not frame then
          frame = CreateFrame( "Frame", nil, UIParent )
          -- set up the frame here
     end
     return frame
end
And then when you want to do something with the frame:

Code:
     frame = frame or InitializeFrame()
     frame:Show()
__________________
“Be humble, for you are made of earth. Be noble, for you are made of stars.”
  Reply With Quote
02-24-11, 09:23 PM   #5
BlueSixty
A Murloc Raider
 
BlueSixty's Avatar
Join Date: Feb 2011
Posts: 6
Smile

Thanks Akkorian,

That really helps and does just what I need
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Destroying hiding a frame


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off