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

TypeError: Error #1006 - Removing MovieClip from the stage

Engaged ,
Feb 28, 2013 Feb 28, 2013

I have a movie clip that is called to the stage and once the movieclip is finished it calls a function that removes it from the stage. The code works but I get an error message about 4 seconds after the movie clip ends.

Here’s the error message:

TypeError: Error #1006: exitWordMicroscopic is not a function.

                at ASvocabulary_microscopic/frame110()[ASvocabulary_microscopic::frame110:1]

Here’s the stage code:

//************************Removes the movieclip from the stage and enables the button.*************************

function exitWordMicroscopic():void

{

                bnt_vocab_microscopic.mouseEnabled = true;

                removeChild(word_Microscopic);

}

//******************************Stage buttons**************************************

stage.addEventListener(MouseEvent.MOUSE_DOWN, goButtonsHomeRead_1);

function goButtonsHomeRead_1(event:MouseEvent):void

{

                //Vocabulary buttons

                if (event.target == bnt_vocab_microscopic)

                {

                                bnt_vocab_microscopic.mouseEnabled = false;

                                SoundMixer.stopAll();

                                addChild(word_Microscopic);

                                word_Microscopic.x = 47;

                                word_Microscopic.y = 120;

                }

}

Here’s the code inside the movie clip. This is what the error message is referring to:

//****************** Calls function to remove itself from the stage****************************

Object(parent).exitWordMicroscopic();

What am I doing wrong?

TOPICS
ActionScript
1.9K
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

correct answers 1 Correct answer

LEGEND , Mar 02, 2013 Mar 02, 2013

There is a more OOP proper way to do this, but for the moment you could use...

Object(parent.parent).exitWordMicroscopic();

function exitWordMicroscopic():void

{

    bnt_vocab_microscopic.mouseEnabled = true;

    mc_EmpytMovie_Micro.removeChild(word_Microscopic);

}

Translate
LEGEND ,
Feb 28, 2013 Feb 28, 2013

Does the movieclip take about 4 seconds to play thru?  I am guessing that it is playing again and when it is done it once again tries to target the parent... only the second time around it has no parent with such a function.

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
Engaged ,
Feb 28, 2013 Feb 28, 2013

Yes it does take four seconds.

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
LEGEND ,
Feb 28, 2013 Feb 28, 2013

You need to stop the movieclip from repeating whatever it does so that it does not execute that request to the parent again. 

When you use the removeChild method you are only removing the targeted object from the display, it still exists and still functions if left to do so.

One other thing you could do after you remove it using removeChild is to null any reference to it...

     removeChild(word_Microscopic);

     word_Microscopic =  null;

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
Engaged ,
Feb 28, 2013 Feb 28, 2013

I added the null statement and stopped the movieClip see below.

However, when I arrive at the frame, after 4 seconds I get the error message without activating the movie clip. In fact the movie clip has not even been added to the stage yet.

Code on Stage

//Removes the movieclip from the stage and enables the button.

function exitWordMicroscopic():void

{

    bnt_vocab_microscopic.mouseEnabled = true;

    removeChild(word_Microscopic);

    word_Microscopic = null;

}

Code in MovieClip

stop();

Object(parent).exitWordMicroscopic();

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
LEGEND ,
Feb 28, 2013 Feb 28, 2013

How/when is the movieclip created?  As I said, it's existence is all that matters, not that it exists on the stage.

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
Engaged ,
Feb 28, 2013 Feb 28, 2013

The movieclip is called from the libray. Here's the code:

//******************************Stage buttons**************************************

stage.addEventListener(MouseEvent.MOUSE_DOWN, goButtonsHomeRead_1);

function goButtonsHomeRead_1(event:MouseEvent):void

{

                //Vocabulary buttons

                if (event.target == bnt_vocab_microscopic)

                {

                                bnt_vocab_microscopic.mouseEnabled = false;

                                SoundMixer.stopAll();

                                addChild(word_Microscopic);

                                word_Microscopic.x = 47;

                                word_Microscopic.y = 120;

                                word_Microscopic.play();

                }

}

I added a stop(); in the beginning of the movieclip. It's 4 second animation. I  added word_Microscopic.play(); to start the movieclip.

However, what if the user goes to the next page (its a book) while the movieclip is playing? Currently, the movieclip stays on the stage on the new page. I am running into an error when the on the next page. I know what's happening but I don't know how to fix it. The movieclip is still playing and calls the function exitWordMicroscopic() which is in the previous frame. How do I fix this?

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
Engaged ,
Feb 28, 2013 Feb 28, 2013

Here' how the code looks now:

Objective: To remove the current movieclip while it's playing so that it does not show on the next (or previous) frame.

Here’s the stage code:

var word_Microscopic:ASvocabulary_microscopic = new ASvocabulary_microscopic();

//Removes the movieclip from the stage and enables the button.

function exitWordMicroscopic():void

{

    bnt_vocab_microscopic.mouseEnabled = true;

    removeChild(word_Microscopic);

}

//******************************Stage buttons**************************************

stage.addEventListener(MouseEvent.MOUSE_DOWN, goButtonsHomeRead_1);

function goButtonsHomeRead_1(event:MouseEvent):void

{

    //Vocabulary buttons

    if (event.target == bnt_vocab_microscopic)

    {

        SoundMixer.stopAll();

        bnt_vocab_microscopic.mouseEnabled = false;

        addChild(word_Microscopic);

        word_Microscopic.x = 47;

        word_Microscopic.y = 120;

        word_Microscopic.play();

    }

//This button takes the user to the Main Screen

    if (event.target == bnt_ReadGoHome_1)

    {

       // exitWordMicroscopic(); [If I use this function I get this error ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.]

        SoundMixer.stopAll();

        gotoAndPlay("1","Main");

        stage.removeEventListener(MouseEvent.MOUSE_DOWN, goButtonsHomeRead_1);

      }

//This takes the user to the next frame.

if (event.target == GoNext_1)

    {

        SoundMixer.stopAll();

        gotoAndPlay("2");

        stage.removeEventListener(MouseEvent.MOUSE_DOWN, goButtonsHomeRead_1);

    }

}

Here’s the code inside the movie clip.

//****************** Calls function to remove itself from the stage****************************

Object(parent).exitWordMicroscopic();

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
Engaged ,
Feb 28, 2013 Feb 28, 2013

I tried a few more things but none have worked.

So one solution I thought of is disabling all navigation buttons until the movieclip is finished. I kind of think that's a cop-out but I'm out of ideas.

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
LEGEND ,
Mar 01, 2013 Mar 01, 2013

I lost track (of keeping track) of your posting after my last response. 

When you dynamically add content, if you do not add it to something that is nailed to a frame in the timeline, then that object has no home in the the timeline and will persist throughout it.  So moving to frame 2 will not get rid of the object... it still exists.

If you could manually place an empty movieclip in the timeline in frame 1 and add the object to that instead of the stage, then it would go away when you leave frame 1.

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
Engaged ,
Mar 01, 2013 Mar 01, 2013

I added an empty movieclip to the stage and and during runtime I add the movieclip inside the empy movieclip.

mc_EmpytMovie_Micro.addChild(word_Microscopic);

In the movieclip that is added to the movieclip how do I communicate back from that movieclip to run the function to remove the movieclip (word_Microscopic)? Currently, I am using:

Object(parent).exitWordMicroscopic();

This function removes the movieclip from the stage.

function exitWordMicroscopic():void

{

    bnt_vocab_microscopic.mouseEnabled = true;

    removeChild(word_Microscopic);

}

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
LEGEND ,
Mar 02, 2013 Mar 02, 2013
LATEST

There is a more OOP proper way to do this, but for the moment you could use...

Object(parent.parent).exitWordMicroscopic();

function exitWordMicroscopic():void

{

    bnt_vocab_microscopic.mouseEnabled = true;

    mc_EmpytMovie_Micro.removeChild(word_Microscopic);

}

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
New Here ,
Mar 01, 2013 Mar 01, 2013

was experiencing the same problem, thanks guys for the valuable tech suport

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