actionscript-3flashmovieclipflash-cs3

Flash CS3 null reference to button/mc after returning to Frame


I've been researching this issue for hours and while I've found somewhat similiar situations, i have yet to find a simple fix. Basically I have a timeline where some animation plays. Eventually I get to my main game screen (frame 256) where a stop(); is called and the user then gets to click on one of 3 doors. Clicking on any door takes the user ahead a bunch of frames and they get to play a game. Once the game is done or the user clicks back, it takes the user back to the original frame (frame 256) and every single time it does this, it says my "upDoor" is a null reference and then the upDoor button(instance of upStairsDoor button) is no longer on the stage.

This seems to happen regardless of which door the user picks first. If the user picks the upDoor and plays the minigame there or picks the outsideDoor and plays that specific minigame, when the user returns to this frame (frame 256), it throws this error on the door and then of course because it throws an error, nothing else works at that point and I have to exit the game.

It's not a typo! Please don't suggest I check my instance names. As I mentioned, the door works fine the first time you get to the frame, it's just when you go back to it. I've read that it might have to do with the garbage collector but when we return to the frame, shouldn't it recreate all of the instances that I've placed to the stage? It doesn't error on ANY other button or movieClip that I've dragged to the stage, only this one particular door.

I forgot to mention that it's error'ing on a line of code that references the upDoor button. I have these lines of code here...(frame 256)

if (downDoor.enabled) {
    downDoor.enabled = false;
}
if (upDoor.enabled) {
    upDoor.enabled = false;
}
if (outDoor.enabled) {
    outDoor.enabled = false;
}

What these do is disable the doors until the user clicks another object on the screen which then runs a function that sets all the doors to enabled. The error in question is saying I can't access a property of a null reference.


Solution

  • Thanks for the input guys. What ended up being the solution for me was to implement all of the movieclips and buttons programatically when the frame loads and then remove them all when I switch frames. That way, everytime the frame is reloaded from a gotoAndPlay, everything gets re-created again.