You need to seperate this into the event that triggers the effect you want to achieve.
I was in the same boat here:
http://www.wowinterface.com/forums/s...ad.php?t=46227
Some good reads are:
http://www.iriel.org/wow/docs/Secure...20-%20pre1.pdf
http://www.wowwiki.com/SecureHandlers
The following secure templates are supported
Lua Code:
SecureHandlerBaseTemplate
SecureHandlerStateTemplate
SecureHandlerAttributeTemplate
SecureHandlerClickTemplate
SecureHandlerDoubleClickTemplate
SecureHandlerDragTemplate
SecureHandlerMouseUpDownTemplate
SecureHandlerMouseWheelTemplate
SecureHandlerEnterLeaveTemplate
If you have a button that should trigger sth onclick you can work with the SecureHandlerClickTemplate.
If sth in your environment changes (group, combat) it is probably best to use the SecureHandlerStateTemplate.
Here is an example for a click handler that will work securely in combat:
Lua Code:
--the frame
local myFrame = CreateFrame("Frame", nil, UIParent)
myFrame:SetPoint("CENTER")
myFrame:SetSize(200,200)
local tex = myFrame:CreateTexture(nil, "BACKGROUND", nil, -8)
tex:SetTexture(1,1,1)
tex:SetVertexColor(0,1,0)
tex:SetAllPoints()
--button
local button = CreateFrame("BUTTON", "mySecureClickButton", UIParent, "SecureHandlerClickTemplate, UIPanelButtonTemplate")
button.text = _G[button:GetName().."Text"]
button.text:SetText("I'm a magic button")
button:SetWidth(button.text:GetStringWidth()+20)
button:SetHeight(button.text:GetStringHeight()+12)
button:SetPoint("CENTER",0,250)
--onclick handler
button:SetAttribute("_onclick", [=[
local ref = self:GetFrameRef("myFrame")
if not ref:GetAttribute("state") then
ref:SetAttribute("state","open")
end
local state = ref:GetAttribute("state")
if state == "closed" then
ref:SetAlpha(1)
ref:SetSize(200,200)
ref:Show()
ref:SetAttribute("state","open")
self.text:SetText("Click to close")
else
ref:SetAlpha(0.4)
ref:SetSize(50,50)
--ref:Hide()
ref:SetAttribute("state","closed")
self.text:SetText("Click to open")
end
]=])
--create a frame reference by name, you can access this frame in your onclick handler later
button:SetFrameRef("myFrame", myFrame)
Inside the secure onclick handler you can do anything you want since you are in secure environment.
Btw...before you start make sure you really need secure handlers. If you never thouch secure frames in any way in your addon you can stay insecure. Insecure frames can show/hide insecure frames even in combat.