Type Function
Object EventListener
Return value none
Revision Current Public Release (2015.2731)
Keywords removeEventListener, event listener
See also object:addEventListener()


Removes the specified listener from the object's list of listeners so that it no longer is notified of events corresponding to the specified event.


Note that nil is a valid value for listener under certain circumstances, so it's not an error to call :removeEventListener() with a nil listener. Bugs may persist if you accidentally use the wrong name for the listener you're trying to remove.


object:removeEventListener( eventName, listener )
eventName (required)

String. Specifies the name of the event whose corresponding listener should be removed from the list.

listener (required)

Listener. Reference to the listener to remove from the list.


-- define motion and limits
local DX, DY = 3, 3
local XMIN, XMAX = 1, display.contentWidth-1
local YMIN, YMAX = 20, display.contentHeight-1

-- create a shape 
local button = display.newRoundedRect( XMIN, YMIN, 150, 50, 5 )
button:setFillColor( 0.4, 0, 1 )
button.strokeWidth = 6
button:setStrokeColor( 0.8 )

-- move the shape until it hits the limits
local function onFrame (event)
    if button.x + button.width/2 > XMAX or button.x < XMIN 
    or button.y + button.height/2 > YMAX or button.y < YMIN then
        -- stop
        Runtime:removeEventListener( "enterFrame", onFrame )
        -- move
        button.x = button.x + DX
        button.y = button.y + DX

-- update the position every frame
Runtime:addEventListener( "enterFrame", onFrame )