API ScriptObject HookScript

From Wowpedia
(Redirected from API Frame HookScript)
Jump to: navigation, search

Securely post-hooks a script handler.

frame:HookScript("handler", func)

Arguments

handler 
String - The handler to hook to, e.g. "OnShow". See Widget handlers.
func 
Function - The function to call; will be passed all arguments relevant for the hooked widget handler type. May not be nil.

Example

The following snippet prints a message when the player clicks a party member's unit frame. Notably, the hook does not taint the original click handler, allowing the frames to continue to target the relevant party members.

for i = 1, 4 do
 _G["PartyMemberFrame"..i]:HookScript("OnClick", function(self, button)
  print(self:GetName() .. " clicked with " .. button)
 end)
end

Notes

  • Just like hooksecurefunc, this can be used to hook secure handlers.
  • If the frame doesn't have an existing function handling "handler", one will be created as if you called Frame:SetScript.
  • Every script handler has at least one argument (the frame itself, usually self). See widget handlers for details on each handler.

Patch history

The Burning Crusade Patch 2.1.0 (2007-05-22): Now hooks securely.