UIHANDLER OnClick

From Wowpedia
Jump to: navigation, search

The OnClick handler is called after the user clicks a button.

(self, button, down)

Arguments

self 
Table - widget being clicked.
button 
String - button used to click the widget. Button:Click and SetBindingClick can be used to supply arbitrary string values for this parameter, while following values correspond to mouse clicks: "LeftButton", "RightButton", "MiddleButton", "Button4", "Button5", ... .
down 
Boolean - true if button is currently held down, and false if it was released.

Details

Example

local taunts = {"I'm a button.", "Quit clicking me.", "That's enough.", "Stop it!", "I'm leaving!"}
local widget = CreateFrame("Button", "TauntingButton", UIParent, "UIPanelButtonTemplate", 0)
widget:SetWidth(200) widget:SetHeight(24) widget:SetPoint("CENTER")
widget:RegisterForClicks("AnyUp")
widget:SetScript("OnClick", function (self, button, down)
 self:SetID(self:GetID() + 1)
 if taunts[self:GetID()] then
  self:SetText(taunts[self:GetID()])
 else
  self:Hide()
 end
end)

The named arguments are also available in XML handlers:

<OnClick>
 self:SetText("You clicked with", button, down and "and you're still holding it!" or "and you've let go.")
</OnClick>

See also