49
edits
m (New page: {{widgetmethod}} Post hooks a script handler (secure). frame:HookScript("handler", function) == Parameters == === Arguments === <!-- List each argument, together with its type --> :("h...) |
m (→Parameters) |
||
| Line 1: | Line 1: | ||
{{widgetmethod}} | {{widgetmethod}} | ||
Sets a function to be called automatically after the original function is called, or "post hook". Works with secure frames. (secure) | |||
frame:HookScript("handler", func) | |||
frame:HookScript("handler", | |||
== Parameters == | == Parameters == | ||
=== Arguments === | === Arguments === | ||
:;handler : string - the name of the handler type, like 'OnShow', 'OnClick'. See [[Widget handlers]]. | |||
: | :;func : function - function to be called. Cannot be 'nil'. | ||
== Summary == | |||
'HookScript' can be used on secure frames, where 'SetScript' would cause "taint" issues and bad UI behavior. Calls each hooked function after calling its original handler function. Any parameters returned by the hooking function will not be discarded, and not be passed to the original handler. Any handler added this way cannot be removed, and will stay until the UI is reloaded. | |||
== | == Examples == | ||
local MyPartyFrame_OnClick = function( self, button ) | |||
print(self:GetName() .. " clicked with " .. button) | |||
end | |||
for i = 1, 4 do | for i = 1, 4 do | ||
local frame = _G["PartyMemberFrame"..i] | local frame = _G["PartyMemberFrame"..i] | ||
frame:HookScript("OnClick", | frame:HookScript("OnClick", MyPartyFrame_OnClick) | ||
end | end | ||
Print notification in chat log when the player clicks a party member's portrait. 'HookScript' works while preserving the security of the unit frame after calling its original handler, where 'SetScript' in this case would not. | |||
== Notes == | == Notes == | ||
* Just like | * Like any event handler, 'func' is called with arguments '(frame, arg1, arg2, ...)', 'event' being 'arg1' for OnEvent handlers. | ||
* If the frame doesn't have a | * Just like {{api|hooksecurefunc}}("handler", func), this can be used on secure code. | ||
* Every script handler has at least one argument (the frame itself, usually ''self''). See [[widget handlers]] for details on each handler. | * If the frame doesn't have a 'func' for 'handler', one will be created as if you called {{api|Frame:SetScript|t=w}}(). | ||
* Every script handler has at least one argument (the frame itself, usually ''self''). | |||
* See [[widget handlers]] for details on each handler. | |||
== See also == | |||
* {{api|hooksecurefunc}} | |||
* {{api|Frame:SetScript|t=w}} | |||
* {{api|Frame:GetScript|t=w}} | |||
* [[Widget handlers]] | |||