CreateFrame

From Wowpedia
Jump to: navigation, search

Creates a new Frame object.

frame = CreateFrame(frameType [, name, parent, template, id])

Arguments

frameType 
string - Type of the frame e.g. "Frame" or "Button".
name 
string? - Globally accessible name to assign to the frame, or nil for an anonymous frame.
parent 
Frame? - Parent object to assign to the frame, or nil to be parentless; cannot be a string. Can also be set with Frame:SetParent()
template 
string? - Comma-delimited list of virtual frames to inherit from.
id 
number? - ID to assign to the frame. Can also be set with Frame:SetID()

Returns

frame 
Frame - The created Frame object or one of the other frame type objects.

Frame types

Possible frame types are available from the UI.xsd file.

Details

  • Frames can not be deleted or garbage collected. But they can be reused/recycled.
  • Fires the frame's OnLoad script, if it has one from an inherited template.

Examples

  • Shows a texture which is also parented to UIParent so it will be hidden when toggling it with Alt-Z
local f = CreateFrame("Frame", nil, UIParent)
f:SetPoint("CENTER")
f:SetSize(64, 64)

local tex = f:CreateTexture()
tex:SetAllPoints(f)
tex:SetTexture("interface/icons/trade_engineering")
Would you press the button?
local btn = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
btn:SetPoint("CENTER")
btn:SetSize(100, 40)
btn:SetText("Click me")
btn:HookScript("OnMouseDown", function(self, button)
	print("You clicked me with "..button)
end)
  • Displays an animated model.
local m = CreateFrame("PlayerModel")
m:SetPoint("CENTER")
m:SetSize(200, 200)
m:SetDisplayInfo(21723) -- Murloc Costume
  • Registers for events being fired, like chat messages and when you start/stop moving.
local function OnEvent(self, event, ...)
	print(event, ...)
end

local f = CreateFrame("Frame")
f:RegisterEvent("CHAT_MSG_CHANNEL")
f:RegisterEvent("PLAYER_STARTED_MOVING")
f:RegisterEvent("PLAYER_STOPPED_MOVING")
f:SetScript("OnEvent", OnEvent)

Patch changes

See also

External links

References