Did you change the event type to “tap” in the removeListenerEvents? [import]uid: 7559 topic_id: 4918 reply_id: 103079[/import]
Yes I changed it in every add, remove, or dispatch call relative to this issue.
-J [import]uid: 21584 topic_id: 4918 reply_id: 103080[/import]
Yes I changed it in every add, remove, or dispatch call relative to this issue.
-J [import]uid: 21584 topic_id: 4918 reply_id: 103081[/import]
Yes, that is supported. You didn’t post your event dispatch code so I wasn’t sure if you were defining the event or not.
I’m assuming you are seeing the proper print messages when the listener should be removed?
One suggestion would be to add “return true” at the end of your listener function. I don’t think that will change anything but is good practice so no other listener gets called. [import]uid: 7559 topic_id: 4918 reply_id: 103083[/import]
Yes all of the print statements are outputting as expected. But, the event listener gets called 2 times if I added, remove, then add the event again.
How should I proceed at this point? Is this something that can be fixed in the next daily build?
-J [import]uid: 21584 topic_id: 4918 reply_id: 103085[/import]
Jay,
I figured out the problem and it has to do with your code creating a local function, “gameSelectListener”, every time “initGameSelectSigns” is called. Since it’s a local function, it loses scope when the initGameSelectSigns ends and the Runtime:removeEventListener can’t remove the Event Listener because the listener address has changed from when it was first created.
The solution is to move the listener outside the function so it’s only created once and it’s address pointer doesn’t change.
Tom [import]uid: 7559 topic_id: 4918 reply_id: 103558[/import]
Thanks Tom. That makes sense. I guess I need to understand the nuances of scope in lua a bit more. I will look into changing my approach.
-J [import]uid: 21584 topic_id: 4918 reply_id: 103561[/import]
Hi every one!
Please, help me! I can’t remove listener. I read other threads about that issue, but it doesn’t work for me. I still can’t make it work!
Here is my code:
-- main.lua
local storyboard = require "storyboard"
storyboard.gotoScene("main\_scene")
-- main\_scene.lua
local storyboard = require("storyboard")
local scene = storyboard.newScene()
function scene:createScene(event)
local group = self.view
local background = display.newImage("Images/background.jpg")
group:insert(background)
end
local index = 0
function animate(event)
index = index + 1
-- some actions
-- animation is implemented here
if index == 120 then
index = 0
end
end
function scene:enterScene(event)
local group = self.view
local background = group[1]
function background:touch(event)
if event.phase == "ended" or event.phase == "cancelled" then
local options =
{
effect = "zoomOutInFade",
time = 400,
isModal = true,
}
storyboard.gotoScene("zoom\_scene", options)
end
end
Runtime:addEventListener("enterFrame", animate)
background:addEventListener("touch", background)
end
function scene:exitScene(event)
Runtime:removeEventListener("enterFrame", animate)
end
function scene:destroyScene(event)
local group = self.view
end
scene:addEventListener("createScene", scene)
scene:addEventListener("enterScene", scene)
scene:addEventListener("exitScene", scene)
scene:addEventListener("destroyScene", scene)
return scene
Animation continues to play on ‘zoom_scene’. Is my ‘animate’ function out of scope in ‘exitScene’? [import]uid: 153428 topic_id: 4918 reply_id: 111972[/import]
One way to find out if “animate” is out of scope and if the exit method is being called is to add a print statement to exitScene.
print( "exitScene: ", animate )
[import]uid: 7559 topic_id: 4918 reply_id: 111982[/import]