Problem with the Director class

Hello,

I’m using the Director class, working with 2 scenes.
When I go from scene 1 to scene 2 the first time everything works fine, but if I do: from scene 1 to scene 2; from scene 2 to scene 1; from scene 1 to scene 2, I’ve got a problem.
The code of scene 2 is something like this:

local scrollNav = require("scrollNav")  
  
local function itemSelected(event)  
 print(event.target) --Here is the problem! It prints once when go into scene 2 for the first time, prints 2 times when go to scene 1 and then to scene 2 and so on...  
end  
  
Runtime:addEventListener("scrollNav.itemSel", itemSelected)  
  

And in the scrollNav.lua got something like this:

local event = { name="scrollNav.itemSel", target=foo }  
Runtime:dispatchEvent(event) --I've checked and it dispatches only once allways  

Please, could anybody help me?

TIA
[import]uid: 44013 topic_id: 11091 reply_id: 311091[/import]

Are you removing the eventListeners in the clean function? It sounds like a cleaning issue. Make sure all of your stuff is being properly removed when switching screens. The automatic cleaning that occurs doesn’t take care of event listeners or timers.

Hope that helps.

-Matt
W2MD [import]uid: 10211 topic_id: 11091 reply_id: 40290[/import]

Hello, Matt!
Thanks for your reply!
Yes, just before switching scene I’ve got this code

Runtime:removeEventListener("scrollNav.itemSel", itemSelected)  

I think so, it must be a cleaning issue. But how I make sure all my stuff is been removed?

[import]uid: 44013 topic_id: 11091 reply_id: 40545[/import]