title: AS3 - Why can't I use stage outside of my root class?
body: <p>I have the following two classes:</p>
  
  <pre><code>package 
  {
      import flash.display.Sprite;
      import flash.events.Event;
  
      public class Main extends Sprite
      {
  
          public function Main():void 
          {
              if (stage) init();
              else addEventListener(Event.ADDED_TO_STAGE, init);
          }
  
          private function init(e:Event = null):void 
          {   
              removeEventListener(Event.ADDED_TO_STAGE, init);
              // entry point
              var test:NewClass = new NewClass(); 
          }
  
      }
  
  }
  </code></pre>
  
  <p>AND</p>
  
  <pre><code>package  
  {
      import flash.display.Sprite;
  
      public class NewClass extends Sprite
      {
  
          public function NewClass() 
          {
              trace(stage.width);
          }
  
      }
  
  }
  </code></pre>
  
  <p>I get the following error:</p>
  
  <p>TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at NewClass()[C:\Documents and Settings\Roma\poo\src\NewClass.as:10]
      at Main/init()[C:\Documents and Settings\Roma\poo\src\Main.as:23]
      at Main()[C:\Documents and Settings\Roma\poo\src\Main.as:15]</p>
  
  <p>Why???</p>