GUI Classes/Button:AddOnTextChanged
Jump to navigation
Jump to search
You can use this method to attach a function to a sham event which is triggered when text changes. The function you pass to this method will be triggered whenever button text changes (when object:Text is used)
Syntax
bool Button:AddOnTextChanged ( function func )
Required Arguments
- func: the function you want to add to a list of functions triggered when text changes
function func( buttonObject btn, string oldText, string newText )
- Parameters which are passed to this function
- btn: button object which was created with Button:Create and the function was attached to
- oldText string containing old text before the text was changed
- newText string containing new text of the button
Returns
- true if function was added successfully
- false otherwise
Example
This example creates a button. The button has two functions attached to it, one is triggered when user clicks the button (to change text on the button) and the other one is triggered when the text has changed (which sets the text back to the old text).
addEventHandler ( "onClientResourceStart", getResourceRootElement( getThisResource( ) ), function( ) --create a button object local button = Button:Create( 0.7, 0.1, 0.2, 0.1, "Hello", true ); -- and attach a function to the button which changes its text button:AddOnClick( changeMyText ); -- add myTextHasChanged to the list of triggered functions when text changes button:AddOnTextChanged( myTextHasChanged ); end ) --setup a function to change the text function changeMyText ( ) local text = button:Text( ) --get the text from the button if text == "Hello" then -- if text of button was "Hello", change it to "World!" button:Text( "World!" ); button:Enabled( false ); end end function myTextHasChanged( btn, oldText, newText ) -- if new text is "World!" then set a timer which will change it back to old text (in this case "Hello") -- and enable the button if newText == "World!" then setTimer( btn:Text, 2500, 1, oldTex ); setTimer( btn:Enabled, 2500, 1, true ); end end
See Also
Button class
Check Box class
Gridlist class
- GridList:Create
- GridList:AutoSizeColumn
- GridList:AddColumn
- GridList:AddRow
- GridList:Clear
- GridList:ItemData
- GridList:ItemText
- GridList:SelectedItem
- GridList:SortingEnabled
- GridList:RowCount
- GridList:ColumnCount
- GridList:InsertRowAfter
- GridList:RemoveColumn
- GridList:RemoveRow
- GridList:ScrollBars
- GridList:SelectionMode
Label class
- Label:Create
- Label:Color
- Label:VerticalAlign
- Label:HorizontalAlign
- Label:GetTextExtent
- Label:GetFontHeight
Memo class
Progress Bar class
- ProgressBar:Create
- ProgressBar:Font
- ProgressBar:LabelColor
- ProgressBar:Progress
- ProgressBar:Text
- ProgressBar:Size
Radio Button class
Scroll Bar class
Static Image class
Tab class
Tab panel class
Text Box class (formally known as Edit)
Window class
- GUISharedFuncs:Alpha
- GUISharedFuncs:BringToFront
- GUISharedFuncs:Dragable
- GUISharedFuncs:Enabled
- GUISharedFuncs:Font
- GUISharedFuncs:MoveToBack
- GUISharedFuncs:Property
- GUISharedFuncs:Text
- GUISharedFuncs:Position
- GUISharedFuncs:Size
- GUISharedFuncs:Visible
- GUISharedFuncs:AddOnClick
- GUISharedFuncs:RemoveOnClick
- GUISharedFuncs:AddOnMouseEnter
- GUISharedFuncs:RemoveOnMouseEnter
- GUISharedFuncs:AddOnMouseLeave
- GUISharedFuncs:RemoveOnMouseLeave