Thread Tools Display Modes
12-27-11, 10:43 AM   #1
Crudor
A Defias Bandit
Join Date: Dec 2011
Posts: 3
Call protected func from Blizzard button

hi,

how do I hook an OnClick event of a blizzard button, e.g. the "CharacterMicroButton", to additionally call a protected function (e.g. the "CancelShapeshiftForm" function) when the button is clicked? is this even possible?

thanks for any hints in advance.

ps.: I posted this here too.
  Reply With Quote
12-27-11, 12:18 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
You'll need to replace the button with a SecureActionButton copy of it.
Notice CharacterMicroButton doesn't use an OnClick handler, but it should work all the same.

lua Code:
  1. local old,new=CharacterMicroButton,CreateFrame("Button","CharacterMicroButton","MainMenuBarArtFrame","SecureActionButton MainMenuBarMicroButton");
  2. CharacterMicroButton=new;-- CreateFrame() will only create the button with the name set and not overwrite the global
  3.  
  4. --  Position and steal portrait texture
  5. new:SetAllPoints(old);
  6. MicroButtonPortrait:SetParent(new);
  7. old:Hide();
  8.  
  9. --  Copy script handlers and apply OnLoad
  10. new:HookScript("OnMouseDown",old:GetScript("OnMouseDown"));
  11. new:HookScript("OnMouseUp",old:GetScript("OnMouseUp"));
  12. new:HookScript("OnEvent",CharacterMicroButton_OnEvent);
  13. CharacterMicroButton_OnLoad(new);
  14.  
  15. --  Now for the secure stuff
  16. new:SetAttribute("type","macro");--         Set to run a macro
  17. new:SetAttribute("macrotext",SLASH_CANCELFORM1);--  Make sure we use the localized slash command
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
12-27-11, 03:00 PM   #3
Crudor
A Defias Bandit
Join Date: Dec 2011
Posts: 3
Thank you very much.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Call protected func from Blizzard button


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off