12.07.2015 Views

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 12 ■ Interacting with Widgets 213The last two are special buttons that register automatically <strong>for</strong> all releasebutton clicks <strong>and</strong> down button clicks, respectively.Once you’ve registered <strong>for</strong> clicks, you can set an OnClick script on the frameto receive the click events. When the client calls an OnClick h<strong>and</strong>ler, it passesthe following arguments:self—The frame object that the h<strong>and</strong>ler was called <strong>for</strong>.button—A string indicating which mouse button was used to click theframe.down—A Boolean flag indicating if the mouse click was triggered by adownward click, rather than the releasing <strong>of</strong> a click.You can run the following code in-game to play with the different mousebuttons <strong>and</strong> the release/press portions <strong>of</strong> a click. Click the game button withmultiple buttons on your mouse to see the differences between them. Also,click <strong>and</strong> hold the button so you can see the difference between the ‘‘up’’ <strong>and</strong>‘‘down’’ portions <strong>of</strong> a click.if not ClickFrame thenClickFrame = CreateFrame(“Button“, “ClickFrame“, UIParent, i“GameMenuButtonTemplate“)endClickFrame:ClearAllPoints()ClickFrame:SetPoint(“CENTER“, 0, 0)ClickFrame:SetText(“Click Frame“)ClickFrame:RegisterForClicks(“AnyUp“, “AnyDown“)ClickFrame:SetScript(“OnClick“, function(self, button, down)local name = self:GetName()print(name, button, down)end)You should see a line <strong>of</strong> output added to your chat frame showing the name<strong>of</strong> the frame, ClickFrame, <strong>and</strong> the button that was clicked along with whetheror not the click captured was on the release <strong>of</strong> the click.<strong>Creating</strong> a Close Button Using TemplatesBecause almost every window in the default user interface has a close button,naturally there is a template you can use to save some time. After the tag in the definition <strong>for</strong> BagBuddy, add the following definition:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!