Wowpedia
Advertisement

Called when the user clicks a button.

(self, button, down)

Arguments

self 
Button - Widget being clicked.
button 
string - "LeftButton", "RightButton", "MiddleButton", "Button4", "Button5", ..., "ButtonN"; however, virtual or overriden clicks have aribtrary values using Button:Click(), SetBindingClick() and SecureHandlerWrapScript().
down 
boolean - True when the button is pressed, false when it is released.

Details

Example

A simple button that tells you how it was pressed.

local button = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
button:SetSize(200, 24)
button:SetPoint("CENTER")
button:RegisterForClicks("AnyUp", "AnyDown")
button:SetScript("OnClick", function (self, button, down)
	self:SetText((down and "Pressed " or "Pressed and released ") .. button)
end)

Alternatively, in XML.

<Button parent="UIParent" inherits="UIPanelButtonTemplate">
	<Size x="200" y="24" />
	<Anchors><Anchor point="CENTER" /></Anchors>
	<Scripts>
		<OnLoad>
			self:RegisterForClicks("AnyUp","AnyDown")
		</OnLoad>
		<OnClick>
			self:SetText((down and "Pressed " or "Pressed and released ") .. button)
		</OnClick>
	</Scripts>
</Button>
Advertisement