Event when removed from stage

Hey,

Does anyone know how to call a certain piece of code when a display object is removed from the stage?

This would be really useful. There is some event called REMOVED_FROM_STAGE in flash. Alternatively does somebody know how to override a method and call its supermethod? That way we can override obj:removeSelf() ?

Thanks
Hoan [import]uid: 22829 topic_id: 17036 reply_id: 317036[/import]

Here’s how you can override removeSelf() or any other built-in display object method for that matter:

local myObject = display.newImage( "image.png" )myObject.cached_removeSelf = myObject.removeSelffunction myObject:removeSelf() -- Your code here -- call original removeSelf() method self:cached_removeSelf()end[/code]But do know that if the object is removed by removing its parent group, then the removeSelf() method won't actually be called so be careful with that. [import]uid: 52430 topic_id: 17036 reply_id: 63923[/import]

Thanks Jonathan

I’m looking for something that will always be triggered when a parent is removed from the stage as well…

I’d rather not keep track of where the . For example, say there is a label with a countdown timer (like “0:48”) and its removed from the screen. Every different place we remove it or a parent, we must also cancel the timer. It would be much cleaner if an event was triggered.

Thanks
Hoan
[import]uid: 22829 topic_id: 17036 reply_id: 63927[/import]