Skip navigation
Currently Being Moderated

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

May 16, 2012 9:43 PM

Tags: #removechild #deactivate

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?

 
Replies

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points