event.target

Type NativeDisplayObject
Event userInput
Revision Release 2024.3703
Keywords userInput, target
See also event.text
native.newTextBox()
native.newTextField()

Overview

A direct reference to the native object associated with the TextField or TextBox event.

Gotchas

On a phase of "submitted" or "ended", use event.target.text to access the input object's text contents. In slight contrast, use event.text to access the object's text contents during an "editing" event.

Example

local defaultField

local function textListener( event )

    if ( event.phase == "began" ) then
        -- User begins editing "defaultField"

    elseif ( event.phase == "ended" or event.phase == "submitted" ) then
        -- Output resulting text from "defaultField"
        print( event.target.text )

    elseif ( event.phase == "editing" ) then
        print( event.newCharacters )
        print( event.oldText )
        print( event.startPosition )
        print( event.text )
    end
end

-- Create text field
defaultField = native.newTextField( 150, 150, 180, 30 )
defaultField:addEventListener( "userInput", textListener )