Label Checkbuttons in XML

Sometimes it's useful to create a Checkbutton entirely in XML. Unfortunately, setting a Checkbutton's label is quirky. As noted in the book, you must access the Checkbutton's internal FontString, like so:

_G[checkButton:GetName() .. "Text"]:SetText("my label here")

So how to set "my label here" in XML? As it turns out, Checkbutton's "text" attribute (inherited from Button) is still useful for storing the label. Sample XML and Lua fragments below:

Snippet


	
		
			Checkbutton_OnLoad(self)
		
	


--Below we GET our label from the Checkbutton's XML "text" attribute, and TRANSFER it
--to the Checkbutton's internal FontString
function Checkbutton_OnLoad(checkButton)
	_G[checkButton:GetName() .. "Text"]:SetText(checkButton:GetText())
end
Posted by protasm at Sat, 26 Mar 2011 17:55:48 +0000