I have an issue with my main game loop. When the player is destroyed, I remove the eventListener for the game loop. However, I get an error from the collisionCheck function that a term is undefined. Even if the collisionCheck is part of the gameLoop and the eventListener has been removed.
if(planeHP <= 0){
removePlayer();
}
public function removePlayer(){
removeEventListener(Event.ENTER_FRAME, moveGameObject);
trace("removed");
}
public function moveGameObject(event:Event){
collisionCheck();
}
I can see the “removed” trace before the error in the output window. The error is always from the collisionCheck function.
Thanks for the help.
The issue was that I have multiple loops in the collisionCheck and the loop calling the removePlayer wasn’t the last one so it would continue on even if I remove the listener. Just had to add a return after the removePlayer() and it fixed the issue.