WoW:API Frame SetScript: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
(Factual correction)
mNo edit summary
Line 1: Line 1:
{{widgetmethod}}
{{widgetmethod}}


Sets the action handler for this frame.
Sets an event handler for a specific event type for this frame.


  frame:SetScript("handler", function)
  frame:SetScript("handler", func)


== Parameters ==
== Parameters ==
=== Arguments ===
=== Arguments ===
<!-- List each argument, together with its type -->
:;handler : string - the name of the handler type, like 'OnShow', 'OnClick'.  See [[Widget_handlers]].
:("handler", func)
:;func : function - the Lua function to call or 'nil' to remove the handler


:;handler : String - The handler to attach func to (OnShow, OnEvent, [[Widget_handlers|et al]])
== Examples ==
:;func : Function - The function to call.  <tt>nil</tt> to remove the handler. <tt>func</tt> is called with arguments <tt>(frame, arg1, arg2, ...)</tt> (<tt>event</tt> being <tt>arg1</tt> for OnEvent handlers)
 
== Example ==
  for i = 1, 4 do
  for i = 1, 4 do
     local frame = getglobal("PartyMemberFrame"..i)
     local frame = _G["PartyMemberFrame"..i]
     frame:SetScript("OnShow", frame.Hide)
     frame:SetScript("OnShow", frame.Hide)
  end
  end
 
Adds an 'OnShow' event handler to all party frames to be called whenever they're shown.
====Result====
All party frames will be hidden whenever they're shown.


  PartyMemberFrame1:SetScript("OnShow", nil)
  PartyMemberFrame1:SetScript("OnShow", nil)
====Result====
Removes whatever 'OnShow' handler was set from 'PartyMemberFrame1'.
Removes the OnShow handler from PartyMemberFrame1.


__NOTOC__
== See also ==
* {{api|Frame:GetScript|t=w}}
* [[Widget_handlers]]

Revision as of 19:01, 16 February 2015

Widget API ← Frame < SetScript

Sets an event handler for a specific event type for this frame.

frame:SetScript("handler", func)

Parameters

Arguments

handler
string - the name of the handler type, like 'OnShow', 'OnClick'. See Widget_handlers.
func
function - the Lua function to call or 'nil' to remove the handler

Examples

for i = 1, 4 do
    local frame = _G["PartyMemberFrame"..i]
    frame:SetScript("OnShow", frame.Hide)
end

Adds an 'OnShow' event handler to all party frames to be called whenever they're shown.

PartyMemberFrame1:SetScript("OnShow", nil)

Removes whatever 'OnShow' handler was set from 'PartyMemberFrame1'.

See also