m
Move page script moved page API hooksecurefunc to WoW:API hooksecurefunc without leaving a redirect
(Added a note about hooking Blizzard frame event handler) |
m (Move page script moved page API hooksecurefunc to WoW:API hooksecurefunc without leaving a redirect) |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 43: | Line 43: | ||
Also note that using hooksecurefunc() may not always produce the expected result. Keep in mind that it actually replaces the original function with a new one (the function reference changes). | Also note that using hooksecurefunc() may not always produce the expected result. Keep in mind that it actually replaces the original function with a new one (the function reference changes). | ||
For | For example, if you try to hook the global function "MacroFrame_OnHide" (after the macro frame has been displayed), your function will not be called when the macro frame is closed. | ||
It's simply because in Blizzard_MacroUI.xml the OnHide function call is registered like this: | It's simply because in Blizzard_MacroUI.xml the OnHide function call is registered like this: | ||
<OnHide function="MacroFrame_OnHide"/> | |||
The function ID called when the frame is hidden is the former one, before you | The function ID called when the frame is hidden is the former one, before you hooked "MacroFrame_OnHide". | ||
The workaround is to hook a function called by "MacroFrame_OnHide": | The workaround is to hook a function called by "MacroFrame_OnHide": | ||
hooksecurefunc(MacroPopupFrame, "Hide", MyFunction) | |||
However, when you want to hook a frame's script handler, it's better to use [[API_Frame_HookScript|Frame:HookScript]] like this: | |||
MacroPopupFrame:HookScript("OnHide", MyFunction) -- the client will call MacroFrame_OnHide(MacroPopupFrame) first followed by MyFunction(MacroPopupFrame) | |||