WoW:SecureHandlerStateTemplate

From AddOn Studio
Revision as of 11:32, 3 June 2009 by WoWWiki>Starlightblunder (Created page with '{{uitech}} '''SecureHandlerStateTemplate''' is one of the SecureHandler templates introduced in Patch 3.0. Those templates exist in order to allow addon code to execute withi...')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

SecureHandlerStateTemplate is one of the SecureHandler templates introduced in Patch 3.0. Those templates exist in order to allow addon code to execute within a restricted environment, where it may perform protected actions but has access only to a limited subset of the API. SecureHandlerStateTemplate executes snippets whenever any attribute prefixed with "state-" changes value, making it ideal for use in combination with SecureStateDriver.

Snippets

The handler executes the following snippets in a restricted environment:

_onstate-identifier (self, stateid, newstate)
The snippet is executed when the "state-identifier" attribute changes value; identifier may be any arbitrary string of one or more characters.
self
Secure frame handle to the frame.
stateid
String - identifier of the changed state.
newstate
Mixed - new value of the "state-identifier" attribute. Note that if the value is not a string, boolean or a number, it'll be replaced with nil -- this a limitation enforced by the restricted environment.

Example

The frame defined in XML below will be shown only if you have a hostile target. Note that the frame also behaves properly in combat, even though it is protected.

<Frame name="MyStateFrame" inherits="SecureHandlerStateTemplate" parent="UIParent" protected="true">
 <Attributes>
   <Attribute name="_onstate-foo" value="if newstate == 'show' then self:Show(); else self:Hide(); end" />
 </Attributes>
 <Scripts>
  <OnLoad>
   SecureHandler_OnLoad(self); -- Our OnLoad handler overwrites this one, so execute it now.
   RegisterStateDriver(self, "foo", "[target=target,exists,harm] show; hide");
  </OnLoad>
 </Scripts>
 <Size x="64" y="64"/>
 <Anchors><Anchor point="CENTER"/></Anchors>
 <Layers><Layer level="OVERLAY">
  <Texture name="$parentTex" file="Icons\Temp" setAllPoints="true" />
 </Layer></Layers>
</Frame>