So, I was playing around with AceGUI and I created the following code:
local frmMain = frame:Create("Frame")
frmMain:SetCallback("OnClose", function(widget) frame:Release(widget) end)
local label = frame:Create("InteractiveLabel")
label:SetColor(255, 255, 255)
label:SetHighlight(255, 255, 0, 0.5)
label:SetCallback("OnClick", function(button) CastSpellByName("Cone of Cold") end)
After clicking the label, WoW fired an error saying the addon tryed to use a function only available to Blizzard. This ain't totally unexpected, but the question is: how can I make this label cast a spell? Do I have to use a secure template? How?
I'm not sure it's even possible to make a secure button with AceGUI, due to all of its frame reuse/recycling behaviors.
Either create your own buttons like so:
-- Create a button:
local button = CreateFrame("Button", "MySecureButton1", frame, "SecureActionButtonTemplate")
button:SetPoint("CENTER", frame, 0, 0)
-- Set the spell attributes:
button:SetAttribute("type", "spell") -- Respond to any click with a spell
button:SetAttribute("spell", "Cone of Cold") -- Set the spell to Cone of Cold
-- Add a background (optional):
button.bg = button:CreateTexture(nil, "BACKGROUND")
button.bg:SetTexture(0, 0, 0, 0.75)
-- Add a font string (optional):
button.text = button:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
button.text:SetPoint("LEFT", button, "RIGHT", 5, 0)
-- Set the text and text color (optional):
button.text:SetTextColor(1, 1, 1)
(There's lots more info and examples on the page Seerah linked, as well as the more specific page for the SecureActionButtonTemplate.)
...or use a library like LibActionButton-1.0, though that may not be the best solution if you don't want your buttons to look like action buttons.
Yeah, that's the main issue, making buttons that don't like action buttons. I'd really like a widget like Interactive Label to be able to cast a spell, even if not in combat, but couldn't find a way to do so. For example, let's say we have labels with the names and classes of players in a party. I wanted to create a system to cast a spell on someone at the party depending on his spec when the label is clicked. Seems the only way to do this is to setup dynamically a action button when I click the label and then click the action button, right?
You'd have to create your secure action button separately, and then dynamically position it over the AceGUI button OnEnter, so that when the user clicked, they actually clicked the secure button, not the AceGUI button. Then you'd want the OnLeave and OnHide handlers for your AceGUI button to hide the secure button and call ClearAllPoints on it (don't forget the last part). You'd also need to hide and ClearAllPoints on your secure button upon entering combat.
Overall, though, this does not sound like a task for which AceGUI is well-suited. Could you give a rough description of your UI as a whole? Is this "cast a spell" button going to be displayed as part of a larger options window, or a smaller status/action window? You may be better of just writing your own UI without AceGUI.