This is not a silly question. It is actually a common stumbling block for folks using Runtime listeners.
First, remember that listen is SSK2 shorthand for Runtime:addEventListener. i.e. We are talking about Runtime listeners here.
Second, Runtime listeners are NOT automatically removed in any situation.
Third, to answer your specific question…
SSK2 provides some ways to handle this:
Best Method (take advantage of finalize event):
local tmp = newCircle( nil, left, centerY, { enterFrame = onEnterFrame } ) function tmp.finalize( self ) ignore( "enterFrame", self ) end tmp:addEventListener( "finalize" )
Can also be written like this:
local function finalize( self ) -- If any of these listeners is attached to the object stop and remove them. ignoreList( { "enterFrame", "accelerometer", "onTwoTouchLeft", "myEvent" } , self ) end local tmp = newCircle( nil, left, centerY, { enterFrame = onEnterFrame, finalize = finalize } )
Second Best, use the autoIgnore() helper:
local function onEnterFrame( self ) -- Abort if the object was deleted AND remove the listener if( autoIgnore("enterFrame",self) ) then return end self.x = self.x + 1 if( self.x \>= right ) then self.x = right ignore( "enterFrame", self ) self.enterFrame = nil end end newCircle( nil, left, centerY, { enterFrame = onEnterFrame } )
This is a bit lazy and has a hidden cost since the code executes every frame. Nontheless, I use this methodlogy often when I know there are only a few of these objects.