title: ActionScript 3 - Stage object is null for first operation
body: <p>I have basically been trying to create a chess game, and it has some basic functionality. I have encountered some runtime errors that I can't seem to fix. I've tried searching around for solutions, and I have found several, but none of them seem to work for me.</p>
  
  <p>I then created a new flash project to see if the error still occurs, just to make sure that it's not another part of my program that is causing the issue.</p>
  
  <p>The stage has a pentagon object (a MovieClip) on it, which has an instance name of PentaGray and a class of Gray. There is an intermediary class called PentaClass.</p>
  
  <p>The Main (document) class:</p>
  
  <pre><code>import flash.display.MovieClip;
  import PentaClass;
  import Gray;
  
  public class Main extends MovieClip
  {
      // public var Natsu:String;
  
      public function Main()
      {
          FairyTail();
      }
  
      public function FairyTail()
      {
          trace("PentaGray = " + PentaGray);
              trace("PentaGray's name is " + PentaGray.name);
              PentaGray.TraceThis();
      }
  }
  </code></pre>
  
  <p>PentaClass class:</p>
  
  <pre><code>public class PentaClass extends Main
  {
  
      public function PentaClass()
      {
      }
  
      public function TraceThis():void
      {
          trace("Fairy Tail :D");
      }
  }
  </code></pre>
  
  <p>Gray class:</p>
  
  <pre><code>public class Gray extends PentaClass
  {
      public function Gray()
      {
          // TraceThis();
      }
  }
  </code></pre>
  
  <p>Running the program like this causes this to be printed to the output window:</p>
  
  <pre><code>PentaGray = null
  TypeError: Error #1009: Cannot access a property or method of a null object reference.
  at Main/FairyTail()
  at Main()
  at PentaClass()
  at Gray()
  at flash.display::Sprite/constructChildren()
  at flash.display::Sprite()
  at flash.display::MovieClip()
  at Main()
  PentaGray = null
  TypeError: Error #1009: Cannot access a property or method of a null object reference.
  at Main/FairyTail()
  at Main()
  </code></pre>
  
  <p>If I change the code in the Main class to:</p>
  
  <pre><code>if (PentaGray)
  {
      trace("PentaGray's name is " + PentaGray.name);
      PentaGray.TraceThis();
  }
  </code></pre>
  
  <p>Then this is output:</p>
  
  <pre><code>PentaGray = null
  PentaGray = [object Gray]
  PentaGray's name is PentaGray
  Fairy Tail :D
  </code></pre>
  
  <p>Also, if I run the function from Gray by uncommenting the statement in its constructor, it works properly, but for my game, I need to run a subclass function from the document class.</p>
  
  <p>What I would like to to know is, why is PentaGray null when the program starts? I thought that the objects that are placed on the stage using the IDE are initialised before any written code runs, but this doesn't seem to be the case.</p>
  
  <p>I've tried using event listeners (ENTER_FRAME and a Timer) but they still didn't solve the issue.</p>
  
  <p>How can I change the program so that the object isn't null when certain code, e.g. the FairyTail() function, is executed? Have I not written my code properly or is this an issue with Flash/ActionScript itself?</p>