Stopping function (rule) problem

Hi, I’m trying to solve this problem for a long time, but with no success :frowning:

I’m using director class…
I’ve got piece of code :

local function wrap (event)  
 if cloud01.x \< -10 then  
 cloud01.x = 520  
 end  
  
 if cloud01.x \> 520 then  
 cloud01.x = -10  
 end  
end  
Runtime:addEventListener( "enterFrame", wrap )  

I It works great if “cloud01” goes offscreen he is wrapped back…
But if I change scene I get this error:

Runtime error  
 /Users/HP6/Desktop/Corona/H&H/menu.lua:119: attempt to compare nil with number  

I think, the problem is: If I change scene rule If cloud01 … still work. So, How can I disable it? I tried to remove event listener, but it doesn’t work.

Thanks for help. [import]uid: 59968 topic_id: 11218 reply_id: 311218[/import]