0
votes

I'm trying to remove the parent and children of movieClip in my flash file using AS3.

The problem that I have is that i can only remove the child and the parent stays on the stage at all time!

this is my code to remove the parent and child:

    removeChild(clip_mc);
    clip_mc = null;
    gotoAndStop(2); 

and this is how i create the movieclip and its children:

                     var clip_mc = new MovieClip();
                     // Add the rectangle graphic
                     clip_mc.addChild(rect);
                     // Add the text field
                     clip_mc.addChild(myText);

                     clip_mc.addChild(pictLdr2);
                     // Put the new movieClip on stage now
                     addChild(clip_mc);
                     // Make the mouse button mode true for the movieclip so user knows it is a button
                     clip_mc.buttonMode = true;     

i thought, adding removeChild(); would remove the parent as well but in my case it will only removes the child and the parent stays on the stage

could someone please advise on this?

Thanks

2
What is the parent in your case? The code isn't clear on that. - Brian
If you have code on different frames, you should put all your code on one frame, the first frame. - moot

2 Answers

1
votes

To remove an object, clip_mc in your case, you can do like this : ( comments into the code )

if(contains(clip_mc)){

    clip_mc.parent.removeChild(clip_mc) // removes clip_mc from it's container 

    trace(contains(clip_mc))            // gives : false

    trace(clip_mc)                      // gives : [object MovieClip]

    clip_mc = null                      // removes the reference of clip_mc

    trace(clip_mc)                      // gives : null

}

Code for test :

var rect:clp = new clp()

var clip_mc = new MovieClip()
    clip_mc.addChild(rect)
    clip_mc.buttonMode = true

addChild(clip_mc)

// of course, we activate this portion just at the end to remove clip_mc
if (contains(clip_mc)){
    clip_mc.parent.removeChild(clip_mc)
    clip_mc = null
}
0
votes

Try using clip_mc.parent.parent.removeChild(clip_mc.parent)