How to delete runtime event on a child in a dipslay group?

The title explains it all, how can i stop the runtime event enterframe of the touchObject in the starGroup:destroy 

function. 

 local object = display.newPolygon( startX, -100, gameValues.vertices["star"] ) object.isStarObject = true local touchObject = display.newCircle( startX, -100, gameValues.circleRad+5 ) --object to be touched touchObject.isVisible = false touchObject.id = "star" touchObject.isHitTestable = true touchObject.isStarObject = true touchObject.touch = objectTouched touchObject.enterFrame = offScreen touchObject:addEventListener("touch", touchObject) Runtime:addEventListener( "enterFrame", touchObject ) -- put both object in there own group and in objectsGroup local starGroup = display.newGroup() starGroup:insert(touchObject) starGroup:insert(object) function starGroup:destroy() Runtime:removeEventListener("enterFrame", self) --this line should be changed display.remove( self ) self = nil end objectsGroup:insert(starGroup)

Adding a finalize listener to touchObject will allow you to remove the enterFrame listener when its parent group is removed. Here’s a blog post I wrote a few years back that goes into detail about finalize events: https://coronalabs.com/blog/2015/05/05/tutorial-the-finalize-api-an-unsung-hero/

Wow thanks for telling me this. It is really helpful.

If only one object in this group, just write

Runtime:removeEventListener("enterFrame", touchObject) 

because you give the enterFrame key to touchObject, not StarGroup.

Adding a finalize listener to touchObject will allow you to remove the enterFrame listener when its parent group is removed. Here’s a blog post I wrote a few years back that goes into detail about finalize events: https://coronalabs.com/blog/2015/05/05/tutorial-the-finalize-api-an-unsung-hero/

Wow thanks for telling me this. It is really helpful.

If only one object in this group, just write

Runtime:removeEventListener("enterFrame", touchObject) 

because you give the enterFrame key to touchObject, not StarGroup.