Monday, April 16, 2012

Why does this secure button fail?

The Button works fine Casting my hearthstone, until I add the OnClick SendChatMessage section, then it just says the message, but does not cast Hearth.

I also tried making the OnClick point to a function in the lua file, but that had the exact same result.
Code:
<Button name="HearthButton" inherits="SecureActionButtonTemplate">
<Size x="16" y="16" />
<Anchors>
<Anchor point="TOPLEFT">
<Offset x="272" y="-72" />
</Anchor>
</Anchors>
<Scripts>
<OnLoad>
this:SetAttribute("unit", "none")
this:SetAttribute("type1", "item")
this:SetAttribute("item1", "item:6948") -- Hearthstone
this:SetNormalTexture("Interface\\Icons\\INV_Misc_Rune_01.blp")
</OnLoad>

-- The <OnClick> below seems to overide the above <OnLoad> action
-- can there only be 1 action on a secure button?
<OnClick>
SendChatMessage("Hearthing to " .. GetBindLocation(), "SAY")
</OnClick>

</Scripts>
</Button>

Thanks in advance for any help you can give|||I figured it out. :)

Ended up removing the <OnClick> idea altogether & moving the ChatMessage to fire on the UNIT_SPELLCAST_START event.|||I've never actually tried what you have above but I'm pretty sure this is a limitation of secure frames, you can't just add an OnClick to them as then it's tainted. They way I would do this would be to use the PreClick and PostClick attributes which are used to call functions before and after a click event. I normally do this is Lua with SetScript but I think this would do the same thing in XML:


Code:
this.SetAttribute("PreClick", ButtonPreClick)
this.SetAttribute("PostClick", ButtonPostClick)

Then you just need define functions called ButtonPreClick and/or ButtonPostClick (or whatever you called them in the above code) and put your SendChatMessage or whatever else you want within that function.

You can even use this method to dynamically update the target or spell (or any other attribute) that the button is about to trigger (though obviously this only works outside of combat).|||thanks for the info, I'll try it :)

No comments:

Post a Comment