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

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

Explorer ,
Dec 06, 2014 Dec 06, 2014

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");

    }

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

Explorer , Dec 06, 2014 Dec 06, 2014

var removeTimer;   

clearInterval(myInterval1);

shpA1.parent.removeChild(shpA1);

Translate
Explorer ,
Dec 06, 2014 Dec 06, 2014

var removeTimer;   

clearInterval(myInterval1);

shpA1.parent.removeChild(shpA1);

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 ,
Dec 06, 2014 Dec 06, 2014

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

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
Explorer ,
Dec 06, 2014 Dec 06, 2014
LATEST

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);

}

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