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

Removing a MovieClip within a conditional statement when reactivating an app.

Engaged ,
May 16, 2012 May 16, 2012

Copy link to clipboard

Copied

I am attempting to have the code check to see if a movieclip is present and if it is then remove it when the user exits (or comes back) the application from the device (through a phone call, menu press etc).

In my app when the user exits the application they are given the option of resuming from the same point or going to the first screen.

If a movie clip is on screen then and the user resumes then there is not a problem.

If a movie clip is on screen and the user clicks restart this is where the probelm occurs and I get an error (or nothing happens, depending on the different coding options i've tried).

My intent here is to have the system check for the movie clip and remove them when the app is reactivated via the restartF  function. Refer to the code section below.

  • There is no problem when I only have the items in blue.
  • There is no problem when I only have the items in blue and green.
  • The problem occurs when the code is in its entirety; blue, green, and orange.
  • I get the following error when I click on the restart button:

TypeError: Error #2007: Parameter child must be non-null.

    at flash.display::DisplayObjectContainer/addChild()

  • Anther fact: All of the variables for each color are declared on different frames:

For example:

Frame 1 (This would represent the statements in blue)

var mywordGrumpy:vocabulary_Grumpy = new vocabulary_Grumpy();

var mywordIncline:vocabulary_incline = new vocabulary_incline();

I have narrowed the problem to the restartF function in the code below:

Code Section:

//Adds pop-up screen and asks would they like to resume or restart.

function onComeBack(event:Event):void

{

    NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;

    if (! modalW)

    {

        modalW = new ModalW();

        addChild(modalW);

        modalW.x = -97;

        modalW.y = -8;

        modalW.resumego.addEventListener(MouseEvent.CLICK,resumeF);

        modalW.restartgo.addEventListener(MouseEvent.CLICK,restartF);

    }

    else

    {

        addChild(modalW);

    }

}

//Triggered by resume touch and takes the user back to where they left.

function resumeF(e:MouseEvent):void

{

    removeChild(e.currentTarget.parent);

    gotoAndStop(so.data.currentFrame,so.data.currentSceneName);

}

//Triggered by restart and takes the user to the main screen. If statements removes the movieclips if present.

function restartF(e:MouseEvent):void

{

    if (addChild(myPlayCredits))

    {

        removeChild(myPlayCredits);

    }

    if (addChild(myPlayAbout))

    {

        removeChild(myPlayAbout);

    }

    if (addChild(myPlayAuthor))

    {

        removeChild(myPlayAuthor);

    }

    if (addChild(mywordGrumpy))

    {

        removeChild(mywordGrumpy);

    }

    if (addChild(mywordIncline))

   {

        removeChild(mywordIncline);

    }

    if (addChild(mywordOodles))

    {

        removeChild(mywordOodles);

    }

    removeChild(e.currentTarget.parent);

    gotoAndStop("1","MainScene");

}

What am I doing wrong?

TOPICS
ActionScript

Views

637

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

correct answers 1 Correct answer

Engaged , May 24, 2012 May 24, 2012

I found the answer:

The variable declarations were not on the same frame as the if/then statements. I solved the problem by adding (for each variable):

var mywordGrumpy:vocabulary_Grumpy = new vocabulary_Grumpy();

var mywordIncline:vocabulary_incline = new vocabulary_incline();

var mywordOodles:vocabulary_oodles  = new vocabulary_oodles();

This solved the problem! At the time the variables were being called they had not been declared, thus they had no value, thus the error message.

Votes

Translate

Translate
Engaged ,
May 24, 2012 May 24, 2012

Copy link to clipboard

Copied

Anybody out there?

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
Engaged ,
May 24, 2012 May 24, 2012

Copy link to clipboard

Copied

LATEST

I found the answer:

The variable declarations were not on the same frame as the if/then statements. I solved the problem by adding (for each variable):

var mywordGrumpy:vocabulary_Grumpy = new vocabulary_Grumpy();

var mywordIncline:vocabulary_incline = new vocabulary_incline();

var mywordOodles:vocabulary_oodles  = new vocabulary_oodles();

This solved the problem! At the time the variables were being called they had not been declared, thus they had no value, thus the error message.

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