Unable to remove a runtime listener

I have created a runtime listener with the below code:

local moveListener = Runtime:addEventListener("touch", move);  

Before I change scene with the director class I want to remove the runtime listener with

Runtime:removeEventListener("touch", move);  
moveListener = nil  
director:changeScene("gameover");  

However on my next scene the listener is still firing touch events. How can I remove the listener? [import]uid: 31694 topic_id: 23967 reply_id: 323967[/import]

I do not believe a Runtime Event Listener returns anything, so assigning to moveListener and setting to nil is not needed. If problem persists, ensure scope of move function when removing and possible wrap your Scene change in a timer.performWithDelay. I will admit that I have not used director since I first started, so others may have more advice.

[import]uid: 21331 topic_id: 23967 reply_id: 96565[/import]

I just added the moveLister var to see if it would make a difference (it didn’t). The problem continues. Not sure what you mean by checking the scope of the move function? It is a local function which makes this even more odd as it shouldn’t be seen from the new scene, but it is… [import]uid: 31694 topic_id: 23967 reply_id: 96569[/import]

Hmmmm… It is hard to tell without code. Until someone with more director experience comes along, did you try timer.performWithDelay() for your scene change? Also, are you using any setFocus() in your move listener? [import]uid: 21331 topic_id: 23967 reply_id: 96573[/import]

Yes I am using a setFocus. PerformWithDelay didnt seem to work. [import]uid: 31694 topic_id: 23967 reply_id: 96577[/import]

Don’t assign to a variable.

Runtime:addEventListener("touch", move);  
  
-- later  
  
Runtime:removeEventListener("touch", move);  

That should be all you need.
Jeff
[import]uid: 14119 topic_id: 23967 reply_id: 96590[/import]

That was actually what I had to start with. I tried the var just as a test. Without the var it makes no difference. I’m still unable to remove the listener. [import]uid: 31694 topic_id: 23967 reply_id: 96595[/import]

I believe the setFocus() may be the culprit. I had the same type of issue. I created a special Destroy() function to mind this issue.

Take some time and REALLY scrutinize your move listener. Use print() statements all over, and find out if the Focus has been let go (setting to nil). This, with some performWithDelay’s, should give your app time to let go Focus of your object.

[import]uid: 21331 topic_id: 23967 reply_id: 96596[/import]

I just commented out most of my move function, including the setFocus(), just to see what would happen and I’m still not able to remove it. [import]uid: 31694 topic_id: 23967 reply_id: 96601[/import]

I may need more code, but we’ll keep trying. Are you sure the addListener is only firing once? [import]uid: 21331 topic_id: 23967 reply_id: 96604[/import]

One problem could be that ‘move’ is out of scope for the removeEventListener function.

The following will not work because ‘move’ is out-of-scope.

local function clean()  
 Runtime:removeEventListener("touch", move);  
end  
  
local function move()  
end;  
  
Runtime:addEventListener("touch", move);  

The following will work:

local move  
  
local function clean()  
 Runtime:removeEventListener("touch", move);  
end  
  
function move()  
end;  
  
Runtime:addEventListener("touch", move);  

You can also make ‘move’ global by removing ‘local’.
Jeff
[import]uid: 14119 topic_id: 23967 reply_id: 96611[/import]

Ya, I stated early on the scope of the move func, but probably should have provided an example of what I meant, thanks Habitat! [import]uid: 21331 topic_id: 23967 reply_id: 96619[/import]

Jeff,

As always you are a genius! If I ever get this project finished I will dedicate it to you.

I appreciate everyones help, this issue is now solved. [import]uid: 31694 topic_id: 23967 reply_id: 96624[/import]

… gotta hate it when that happens… LOL! looks like we both learned something, you scope, me better posting… :slight_smile: [import]uid: 21331 topic_id: 23967 reply_id: 96629[/import]

Oh so that is what you meant by “ensure scope of move function”… Duh… [import]uid: 31694 topic_id: 23967 reply_id: 96696[/import]