API CreateFrame

101,278pages on
this wiki
Revision as of 01:47, October 21, 2010 by Peeka (Talk | contribs)

(diff) ←Older revision | Latest revision (diff) | Newer revision → (diff)
WoW API < CreateFrame

Creates a new UI frame.

newFrame = CreateFrame("frameType"[, "frameName"[, parentFrame[, "inheritsFrame"]]]);

Parameters Edit

Arguments Edit

String - Type of the frame to be created (XML tag name): "Frame", "Button", etc. See UIOBJECT_Frame
String - Name of the newly created frame. If nil, no frame name is assigned. The function will also set a global variable of this name to point to the newly created frame.
Frame - The frame object that will be used as the created Frame's parent (cannot be a string!) Does not default to UIParent if given nil.
String - a comma-delimited list of names of virtual frames to inherit from (the same as in XML). If nil, no frames will be inherited. These frames cannot be frames that were created using this function, they must be created using XML with virtual="true" in the tag.

Returns Edit

Frame - Pointer to the newly created frame.

Example Edit

Result: displays the horde and alliance insignias in the middle of the screen.

local f = CreateFrame("Frame",nil,UIParent)
f:SetWidth(128) -- Set these to whatever height/width is needed 
f:SetHeight(64) -- for your Texture

local t = f:CreateTexture(nil,"BACKGROUND")
f.texture = t


Notes Edit

  • CreateFrame() was added in 1.10
  • The fourth argument, inheritFrame, was added in 1.11
  • Frames CANNOT be deleted. Reuse them.
  • The frame's OnLoad handler, which will only exist if inherited, will be executed during the CreateFrame call. Any OnLoad script handlers set after CreateFrame() will not execute; consider adding any non-inherited OnLoad code directly after a CreateFrame call or use XML frames instead.
  • The returned pointer is not necessary if you pass a frame name, however it is advised you store the pointer in a local instead of using the global name whenever possible for performance reasons.
  • See also API_Frame_SetScript to handle OnFunction scripts when not using a template.
  • The most common uses for this function are:
    • Creating anonymous event handlers.
    • Creating anonymous script handlers.
    • Creating frames on the fly for occasions when you don't know how many frames will be needed.
    • Creating infrequently used frames "on demand", for example: config dialogs, raid frames.
  • 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).

Around Wikia's network

Random Wiki