Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to removechild IF it's visible

Contributor ,
Oct 31, 2013 Oct 31, 2013

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 !

TOPICS
ActionScript
467
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Oct 31, 2013 Oct 31, 2013

if(this.parent.introScreen != null){

   this.parent.removeChild(introScreen);

}

else{

  //do nothing

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 31, 2013 Oct 31, 2013
LATEST

Thanks !

But someone told me an other solution that's working :

if (introScreen.parent) {
    introScreen
.parent.removeChild(introScreen);
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines