![]() |
Wowpedia is no longer updated, go away. |
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[]
- Button:RegisterForClicks() controls which mouse interactions will fire OnClick (defaults to "LeftButtonUp")
- Preceeded by OnMouseDown, OnMouseUp and PreClick; and followed by PostClick.
- Blocked in the "up" direction by OnDoubleClick when it fires.
- Blocked in the "up" direction after dragging with a button registered for dragging, or any time if the cursor is moved off the widget and not brought back before releasing the mouse button.
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>