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

How to removechild IF it's visible

Contributor ,
Oct 31, 2013 Oct 31, 2013

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 !

TOPICS
ActionScript

Views

426

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

   this.parent.removeChild(introScreen);

}

else{

  //do nothing

}

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

Thanks !

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

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

Votes

Translate

Translate

Report

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