# Did a removeChild() but child keeps running

**URL:** <https://forum.kirupa.com/t/did-a-removechild-but-child-keeps-running/324695>\
**Category:** flash\
**Created:** [September 3, 2011, 6:21pm UTC](https://forum.kirupa.com/t/did-a-removechild-but-child-keeps-running/324695 "2011-09-03T18:21:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tpann](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@tpann](https://forum.kirupa.com/u/tpann)\
**Post date:** [September 3, 2011, 6:21pm UTC](https://forum.kirupa.com/t/did-a-removechild-but-child-keeps-running/324695/1 "2011-09-03T18:21:25Z")

</div>

I have an animation in a class, P2, that extends Sprite that I call from the Flash IDE. I have a button that removes the class at any time using removeChild();

P2 is a series of functions that each animate one or a couple of images using Tweener. Each function calls the next function either using an onComplete parameter in the Tweener.addTween object or by starting a timer with a single repeat count and calling the next function upon TIMER\_COMPLETE.

P2 looks sort of like this:

```php

package {
     import flash.display.*;
     import flash.events.*;
     import flash.utils.Timer;
     import caurina.transitions.*;
    
     public class P2 extends Sprite {
          private var mc1:MC1;
          private var mc2:MC2;
          // etc. lots more movie clips
         
          private var myTimer:Timer;
         
          public function P2():void {
               mc1 = new MC1();
               mc2 = new MC2();
               //etc.
               addEventListener(Event.ADDED_TO_STAGE, startAnimation);
          }
          private function startAnimation():void {
               trace("startAnimation");
               Tweener.addTween(mc1, {x:100, time:1, transition:"linear"});
               Tweener.addTween(mc2, {x:100, time:1, transition:"linear", onComplete:start02});
          }
          private function start02():void {
               trace("start02");
               Tweener.addTween(mc3, {alpha:1, transition:"linear"});
               dispatchEvent(new CustomEvent(CustomEvent.MC3_STARTED});
               timer = new Timer(2000, 1);
               myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, start03);
               myTimer.start();
          }
          private function start03(e:TimerEvent):void {
               trace("start03");
               myTimer.stop();
               Tweener.addTween(mc4, {alpha:1, x:320, transition:"linear", onComplete:start04});
          }
          private function start04():void {
               trace("start04");
               //etc. etc. you get the point
          }
     }
}

```

Pretty straightforward. Then, in the Flash IDE, when I click my button to quit, I have this:

```php
var p2:P2 = new P2();
addChild(p2);
btn.addEventListener(MouseEvent.CLICK, closeP2);
function closeP2(e:MouseEvent):void {
     if (p2) {
          if (p2.parent != null) removeChild(p2);
     }
}

```

When I click the button, all of the images disappear so obviously the removeChild(p2) did something. However, the trace statements in each function continue to trace. Even though I removed p2, it’s still running.

What is the explanation for this? I thought removeChild() got rid of it completely. Is there some other way to completely get rid of p2?
