Skip to main content
mcaloney_d
Inspiring
December 6, 2014
Answered

How do I remove a child from the stage using a button click?

  • December 6, 2014
  • 2 replies
  • 1173 views

I have a movieclip that requires Play, Pause, Forward and Back buttons. The movieclip has actionscript at various frames to load movieclips from the library and repeat them.

I have tried using a timeline scrubber but it does not trigger the actionscript when scrubbing, only when the movie plays normally.

My possible solution is to create Fwd and Back buttons that can go to specific frames where key animations will begin.

I need to develop actionscript that will remove Children when the user clicks Back.

This is how I am loading several movieclips along the timeline from my library:

var shpA1:arSHPp1;

function attachAR1 () {

  shpA1 = new arSHPp1 ();

  shpA1.x = -30;

  shpA1.y = 18;

  addChild (shpA1);

  }

//the interval is used to repeat the animation to represent continuous flow on a diagram

var myInterval1:uint = setInterval (attachAR1, 500);



This what I have tried so far (not working at all - no errors or trace):

function remChild1(event:MouseEvent) :void {

    if(shpA1.stage)

    {

        trace("arSHPp1 is in display list");

        shpA1.parent.removeChild(shpA1);

        shpA1 = null

    }

    else

    {

        trace("arSHPp1 isn't in display list");

    }

This topic has been closed for replies.
Correct answer mcaloney_d

var removeTimer;   

clearInterval(myInterval1);

shpA1.parent.removeChild(shpA1);

2 replies

Ned Murphy
Legend
December 6, 2014

If you used addChild(shpA1);  and can target it directly then you should only need to use removeChild(shpA1);

mcaloney_d
Inspiring
December 7, 2014

I did try that but it would not remove the child.

i appreciate your help though.

I am also trying to determine if a child is on the stage and if it is, remove it. I have created a button that will jump back on the timeline and the mc's that were loaded after this point in time.

This looks like it should work. It doesn't give me any errors but the mc remains on the stage.

var remMC;

if (getChildByName("mc2") != null) {

  removeChild(mc2);

}

mcaloney_d
mcaloney_dAuthorCorrect answer
Inspiring
December 6, 2014

var removeTimer;   

clearInterval(myInterval1);

shpA1.parent.removeChild(shpA1);