Copy link to clipboard
Copied
I'm making a game in AS3 when you can save and restore your game.
The player can load his saved game at the introscreen OR during the game.
I've got an error (not very important as the game is still working but I'd like to correct in order to be clean) as I don't know how to put it in code.
So, when the player click on "load" at the Introscreen, a window opens where he can choose wich games he wants to restore.
When he choose a game, he click on it and the IntroScreen AND the restore window disappear. Here's the code for this :
if(allSaveData){
..
dispatchEvent(new Event("closeThis"));
this.parent.removeChild(introScreen);
}
But when he's in the game and he wants to restore. He clicks on "esc" and the restore windows appears. But the IntroScreen IS NOT HERE. So when he restore his game, I've got an error with "this.parent.removeChild(introScreen);" as IntroScreen is not here.
I've tried this :
if(allSaveData){
..
dispatchEvent(new Event("closeThis")); }
if (introScreen.visible == true){
this.parent.removeChild(introScreen);
}
But it's not working. Do you know how I can tell the code "if introscreen is here close it, if not don't" ?
Thank you for your help !
Copy link to clipboard
Copied
if(this.parent.introScreen != null){
this.parent.removeChild(introScreen);
}
else{
//do nothing
}
Copy link to clipboard
Copied
Thanks !
But someone told me an other solution that's working :
if (introScreen.parent) {
introScreen.parent.removeChild(introScreen);
}