how to remove functions when exiting a scene in storyboard

I need to remove my touch event which is a function in the exit scene function in storyboard.

I don’t use Storyboard, so not sure if I am not understanding something specific to that, but in general you add an event like this:

myImage:addEventListener( "touch", myFunction )

And then remove it like this:

myImage:removeEventListener( "touch", myFunction )

Is that not working, or not what you are looking for?

In general you don’t need to remove touch and tap handlers if the objects are managed by storyboard.  Once the scene transitions off the screen, you can’t interact with them any longer.  When the scene is purged or removed, the objects no longer exist so you don’t need to deal with it then. 

I suspect that it’s possible if you use a crossFade or fade transition where the old scene ends up underneath the current scene that touch events could fall through, but it’s easy enough to put a touch/tap handler on the background to catch anything else.

The problem with removing them, is you have to remember to add them back in when the scene reloads because unless you’re purging the scene or removing it, the createScene event won’t re-fire.  If you delay adding your touch handler to enterScene then you can remove them in exitScene.  You just have to make sure the objects are visible to the whole scene, not just to the function where you create them.

Rob

I set it so on collision it goes to the next scene so when I go to the next scene it is good but when I touch it has an error and brings me to my previous .lua file and goes to the applyForce.

So this objects is not being managed by storyboard?  It exists between scenes?

Can you post  your code where you are creating the touch listener and where you are trying to cancel it?

Rob

my button does not work anymore. Like I go into the game then on collision it goes to the next scene which is a restart screen and the button that I direct back to the game does not work 

Can you post more of your code?  Are you getting any errors in your console log?

I don’t use Storyboard, so not sure if I am not understanding something specific to that, but in general you add an event like this:

myImage:addEventListener( "touch", myFunction )

And then remove it like this:

myImage:removeEventListener( "touch", myFunction )

Is that not working, or not what you are looking for?

In general you don’t need to remove touch and tap handlers if the objects are managed by storyboard.  Once the scene transitions off the screen, you can’t interact with them any longer.  When the scene is purged or removed, the objects no longer exist so you don’t need to deal with it then. 

I suspect that it’s possible if you use a crossFade or fade transition where the old scene ends up underneath the current scene that touch events could fall through, but it’s easy enough to put a touch/tap handler on the background to catch anything else.

The problem with removing them, is you have to remember to add them back in when the scene reloads because unless you’re purging the scene or removing it, the createScene event won’t re-fire.  If you delay adding your touch handler to enterScene then you can remove them in exitScene.  You just have to make sure the objects are visible to the whole scene, not just to the function where you create them.

Rob

I set it so on collision it goes to the next scene so when I go to the next scene it is good but when I touch it has an error and brings me to my previous .lua file and goes to the applyForce.

So this objects is not being managed by storyboard?  It exists between scenes?

Can you post  your code where you are creating the touch listener and where you are trying to cancel it?

Rob

my button does not work anymore. Like I go into the game then on collision it goes to the next scene which is a restart screen and the button that I direct back to the game does not work 

Can you post more of your code?  Are you getting any errors in your console log?