Thread: Custom Scripts
View Single Post
07-28-14, 06:04 AM   #9
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by kurapica.igas View Post
Well, if you only need one event handler for one frame's event, it's simple to do it , just add one method to your frame, like :

Lua Code:
  1. ------------------------------
  2. -- Template part
  3. ------------------------------
  4. local function Fire(self, event, ...)
  5.     return type(self[event]) == "function" and self[event](self, ...)
  6. end
  7.  
  8. local function OnClick(self)
  9.     return self.Parent:Fire("OnValueChanged", self:GetID())
  10. end
  11.  
  12. function CreateDropDownMenu( ... )
  13.     local menu = CreateFrame("Frame", ...)
  14.  
  15.     -- Give it a new method
  16.     menu.Fire = Fire
  17.  
  18.     -- Create menu buttons
  19.     for i = 1, 10 do
  20.         local btn = CreateFrame("Button", nil, menu)
  21.         btn:SetID(i)
  22.         btn.Parent = menu
  23.  
  24.         btn:SetScript("OnClick", OnClick)
  25.     end
  26.  
  27.     return menu
  28. end
  29.  
  30. ------------------------------
  31. -- Test part
  32. ------------------------------
  33. local menu = CreateDropDownMenu()
  34.  
  35. function menu:OnValueChanged(value)
  36.     -- action
  37. end
I think this is what i need. Thanks.
  Reply With Quote