Documentation / XML guide
Scripts and load order
Script handlers, append and prepend, and when OnLoad and OnShow run.
Writing a handler
A handler can be written three ways:
<Scripts>
<OnLoad method="OnLoad"/> <!-- self:OnLoad(), from a mixin -->
<OnShow function="MyWindow_OnShow"/> <!-- a global function -->
<OnClick>
print(self:GetName(), button, down) -- a body
</OnClick>
</Scripts>
method="OnLoad"callsself:OnLoad(...), usually a function from a mixin.function="Name"calls a global function. If there is no such function when the frame is built, the handler is left out and Lizzard says so.- A body is Lua. It gets
self, then names for the script's arguments, then....
The argument names a body gets, from the names Blizzard's own bodies use:
| Script | Arguments after self |
|---|---|
| OnClick | button, down Measured (Retail) |
| OnDoubleClick, OnMouseDown, OnMouseUp, OnDragStart | button |
| OnEnter, OnLeave | motion |
| OnEvent | event, then the event's own values in ... |
| OnUpdate | elapsed |
| OnSizeChanged | width, height |
| OnValueChanged | value, userInput Guessed order |
| OnTextChanged | userInput |
| OnKeyDown, OnKeyUp | key |
| OnMouseWheel | delta |
| OnVerticalScroll, OnHorizontalScroll | offset |
A template's handler and your own
When a template already has a handler for a script, the element's own handler replaces it, unless
it says inherit="append" or inherit="prepend". Then both run, in an order that reads the
wrong way round:
<Frame name="MyPanelTemplate" virtual="true">
<Scripts>
<OnLoad>print("template")</OnLoad>
</Scripts>
</Frame>
<Frame name="MyPanel" inherits="MyPanelTemplate">
<Scripts>
<OnLoad inherit="append">print("own")</OnLoad>
</Scripts>
</Frame>
When OnLoad runs
A frame's OnLoad doesn't run the moment the frame is made. Lizzard waits until the outermost frame being built is complete, every child and template included. Then OnLoad runs for each frame built, children before their parents.
- After all the OnLoads, OnShow runs, in the same order, for each frame from XML that is shown. Measured (Retail) that it runs: the game's party frame makes its members in OnShow. Guessed the order.
CreateFramein Lua applies the templates, then runs OnLoad the same way. It doesn't run OnShow. Guessed- In an intrinsic type's own element (intrinsic types),
intrinsicOrder="postcall"runs that handler after the frame's own; otherwise it runs before.