For a more complete change-spell-on-state example:
Code:
local sBtn = CreateFrame("Button", nil, UIParent, "SecureActionButtonTemplate"); -- [1]
parentHeader:SetAttribute("addchild", sBtn); -- [2]
sBtn:SetAttribute("statebutton", "1:state1;2:state2;3:state3"); -- [3]
local spells = {"Immolation Trap", "Frost Trap", "Snake Trap"};
sBtn:SetAttribute("type", "spell"); -- [4]
for i=1,#spells do
sBtn:SetAttribute("*spell-state"..i, spells[i]); -- [5]
end
- Create a SecureActionButton to do things with. There's no skin included here -- you'd need to add your own textures, dimensions and anchors to actually see the action button.
- parentHeader is the SecureStateHeader whose state this button will alter behavior based on. Setting the "addchild" attribute on a SecureStateHeader fires its SecureStateHeader_OnAttributeChanged, which applies the necessary changes to the child -- like replacing the child's OnClick handler with SecureStateChild_OnClick.
- This attribute makes SecureStateChild_OnClick change the button attribute passed to SecureActionButton_OnClick (the default OnClick handler for a SecureActionButton) based on the header's state. In this case, if the header is in state 1, the SAB thinks the button "state1" was used to click it; same with "state2" in state 2 and "state3" in state 3. The attribute's general syntax is "state:newbuttonstring;otherstatetherbuttonstring;...".
- All three actions are spells, so we do not have to bother with modifying the "type" attribute based on anything.
- Both "type" and "spell" attributes are retrieved using SecureButton_GetModifiedAttribute. So, in this attribute's name ("*spell-state{i}", where {i} is replaced by numbers 1 to 3 depending on the iteration of the for loop):
- "*" prefix enables all modifier combinations.
- "spell" is the actual unmodified attribute name.
- "-state{i}" is the button this attribute is valid for. The state1, state2, state3 buttons are the result of the "statebutton" attribute set above.