title: How to restart an AS Class animation
body: <p>I want to remove and re-add/"restart" the Main class when it finishes animating. All of my animations are happening in Main and are added to the display tree inside Main. Program.as handles all this by adding/removing Main. How can I run the <code>finishNow()</code> function inside Main.as? It all works fine, except throws an error for <code>program.finishNow();</code>:<br/>
  <br/>
  TypeError: Error #1009: Cannot access a property or method of a null object reference.
  <br/>
  <br/></p>
  
  <p>The .fla file:</p>
  
  <p>Linked to Program.as.</p>
  
  <p>The Program.as file:</p>
  
  <pre><code>package  {
  
      import flash.display.MovieClip;
  
      public class Program extends MovieClip {
  
  
          public function Program() {
  
              startNow();
          }
  
          function startNow() {
              var run:Main = new Main(this);
              addChild(run);
          }
  
          function finishNow() {
              removeChild(run);
              var run:Main = new Main(this);
              addChild(run);
          }
  
      }
  
  }
  </code></pre>
  
  <p>The Main.as file:</p>
  
  <pre><code>package {
  
      import flash.display.Sprite;
  
      public class Main extends Sprite
      {
  
          var stageHolder:Object;
          public var program:Program;
  
          public function Main(stageHolderTemp) {
              stageHolder = stageHolderTemp; 
              trace(stageHolder);
  
              someFunctionsThatDrawGraphics();
          }
  
          function callFinishFunction():void {
              // how to call finishNow() function from Program.as file here?
              program.finishNow();
          }
  
      }
  }
  </code></pre>