Runtime Listener Question

I coded my in-game menu as a module, so I can call my menu on any level. In this menu I have a button to quit to title screen. The problem comes when I try to remove the runtime event listener located outside of my menu module. The event listener is part of my level.lua file. When I call the Runtime:removeEventListener("enterFrame", main), it doesn't remove the event listener. Is it possible to remove the event listener in this way or can it only be removed from inside the level.lua file? I would greatly appreciate any help, thank you.

You could wrap the remove listener call inside its own function and call the function from the other file.

I will give it a try. I assumed since Runtime is global that I would be able to remove it from an external module without a problem.

Ok I tried what you suggested and it the function fires properly, but it refuses to remove the listener. I inserted print statements and verified that the function is working. I'm really stumped why I cannot remove this event listener. Any ideas??

Just a thought: is it possible that you are programmatically creating more than one Runtime/enterFrame listener? Like each time you create a level you duplicate the listener? If so you might only be removing one instance of the listener.

Let's say you finish level one and advance to level two without removing the listener. Then in level two you call the menu. This call removes the listener initiated in level two, but the listener in level one remains.

May not be what is going on in your app, but it is all I can think of at the moment.

Thanks for your suggestions. But I am positive I only have one Runtime event listener. I can verify that I can remove the event listener by calling the removeEventListener from within the level.lua file. But I am unable to remove it by wrapping it in a function within the level.lua and calling that function from my menu.lua. Pretty weird because I assumed that it would work. I'm not even sure if what I am trying to do is possible. I'm hoping someone who knows the answer comes across my topic!!

Ok I figured it out. I was able to use your method. I just had to enter the function underneath my Runtime enterFrame function in my level file. Jeez what a headache!! Live and learn I guess :)

views:1798 update:2011/9/25 12:40:18
corona forums © 2003-2011