Thread Tools Display Modes
01-30-14, 06:57 AM   #1
Spawnova
A Warpwood Thunder Caller
 
Spawnova's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2012
Posts: 96
How to add click event to a frame

I want to be able to add events to my frame when I left and right click but frames cannot have click events.

So I was wondering if there was a workaround, like an invisible button or something?
  Reply With Quote
01-30-14, 07:31 AM   #2
Malsomnus
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Apr 2013
Posts: 203
Frames might not have click events, but they have MouseDown and MouseUp, which also let you know which button was pressed.

Lua Code:
  1. MyFrame:SetScript("OnMouseDown", function (self, button)
  2.     if button=='LeftButton' then
  3.         print ('OMG left button?!')
  4.     end
  5. end)
__________________
SanityCheck - If you've ever said the words "Sorry, I forgot" then you need this add-on.

Remember, every time you post a comment on an add-on, a kitten gets its wings!
  Reply With Quote
01-30-14, 08:41 AM   #3
Spawnova
A Warpwood Thunder Caller
 
Spawnova's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2012
Posts: 96
Thanks man, appreciate it.
  Reply With Quote
01-30-14, 01:02 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Your other option would be to make your frame a Button object instead of a Frame object; it won't look any different (unless you also have it inherit from some kind of button template) and users won't be able to tell the difference, but it will support an actual OnClick script. This will only matter if what you want to do on "click" requires a hardware event -- if it does, then you need OnClick; you can't do that stuff in OnMouseDown/OnMouseUp.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
01-31-14, 02:33 AM   #5
Spawnova
A Warpwood Thunder Caller
 
Spawnova's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2012
Posts: 96
Thanks phanx, for now the SetScript works perfectly however I'm definitely going to use yours for some others addons I have, thanks.

Also, this is somewhat off topic but does anyone know of an addon or someway to see the resources currently running addons are using?
  Reply With Quote
01-31-14, 03:40 AM   #6
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
http://www.wowinterface.com/download...ddonUsage.html
  Reply With Quote
01-31-14, 10:15 AM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
I use this one:http://www.wowinterface.com/download...tionHouse.html

It may be in the outdated category, but it still works perfectly.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
02-02-14, 02:12 AM   #8
pelf
Sentient Plasmoid
 
pelf's Avatar
Premium Member
Join Date: May 2008
Posts: 133
The event CPU usage tracking portion of the performance monitoring API is broken, FYI. The rest of it is working, though, I think.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How to add click event to a frame

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off