Links |
---|
Registers a frame to monitor for events.
success = frame:RegisterEvent(event)
Arguments
- event
- string - The name of the event to register the object as monitoring.
Returns
- success
- boolean - True when frame is successfully registered to a new event; otherwise false, such as if the frame was already registered to this event.
Details
- Widgets are usually notified of an event in order they were registered, but Frame:UnregisterEvent tends to move the last-registered widget up to fill the gap. Consequently, this behaviour should not be relied upon.
Example
-- Create a frame
local f = CreateFrame("Frame")
-- Register to monitor events
f:RegisterEvent("CHAT_MSG_YELL")
f:RegisterEvent("CHAT_MSG_SAY")
-- Handle the events as they happen
f:SetScript("OnEvent", function(self, event, ...)
if (event == "CHAT_MSG_YELL") then
print("Argh, stop with the yelling!")
elseif (event == "CHAT_MSG_SAY") then
print("Thanks, that was much softer.")
end
end)
Patch changes
Patch 8.0.1 (2018-07-17): Registering a non-existing event now raises an error instead of returning nil.
See also
- The Handling events guide
- Frame:UnregisterEvent("event")
- Frame:RegisterUnitEvent("event", "unit1"[, "unit2"])
- Events