title: ActionScript 3: MovieClip added to Stage not appearing or working
body: <p>I'm making a simple game in Adobe Flash CS4 using ActionScript 3. I recently implemented a new, very small preloader to replace the placeholder that I was using.  However, once I did this, I seemed to break everything.</p>
  
  <p>The first frame has only a <code>stop();</code> in "Actions" and then a DocumentClass external class file (all of my classes are external) that sets up the preloader, which is in its own class file. Once the preloader is done, it fires off an Event to the DocumentClass, which runs a <code>gotoAndStop(3);</code>.  On slide three is a movie clip titled <strong>Main</strong>, with its own class file.</p>
  
  <p><strong>Main</strong> imports a bunch of stuff, then loads the opening screen of the game.  At this point everything basically breaks down.  Any attempts to modify things that are on this opening screen (which has both a class file and MovieClip object) results in "TypeError: Error #1009: Cannot access a property or method of a null object reference."  I thought this code might be running before the MovieClip is on the stage, so I added <code>addEventListener( Event.ADDED_TO_STAGE, onAddtoStage );</code> and moved the code to an <code>onAddtoStage</code> function; while doing <code>trace("this is the stage: "+stage);</code> and <code>trace("this is my parent: "+this.parent);</code> will return the proper, non-null values, I still can't modify anything (for example, making a MovieClip object I'd like to hide invisible by setting <code>invisibleBG.alpha = 0;</code> still returns Error #1009).</p>
  
  <p>Furthermore, while the <strong>Main</strong> MovieClip is visible on the stage, the opening screen MovieClip doesn't show up. I'm not sure if it's <em>behind</em> the <strong>Main</strong> object somehow, but it seems like it's simply not on the stage at all.</p>
  
  <p>There's some of my code below. I can add more if this doesn't show what the problem is. I've been really scratching my head over this; of course, it took me two days to figure out I couldn't modify a <code>TextField</code> because it was stretched out over two frames, so there might be a very simple solution.  Thanks in advance for your help!</p>
  
  <p>Here's most of the class that handles the initial loading:</p>
  
  <pre><code>public class DocumentClass extends MovieClip  
  {
      public var loadingScreen:LoadingScreen;
  
      public function DocumentClass()
      {
          loadingScreen = new LoadingScreen();
          addChild( loadingScreen );
  
          stage.stageFocusRect = false;
  
          loadingScreen.addEventListener( Event.COMPLETE, onPreloaderComplete );
          loadingScreen.setLoaderInfo( loaderInfo );
      }
  
      public function onPreloaderComplete( e:Event ):void
      {
          loadingScreen.removeEventListener( Event.COMPLETE, onPreloaderComplete );
          removeChild( loadingScreen );
          loadingScreen = null;
  
          gotoAndStop( 3 );
      }
  }
  </code></pre>
  
  <p>Here's the relevant portion of the <strong>Main</strong> class: </p>
  
  <pre><code>public class Main extends MovieClip
  {
      public function Main()
      {
          showDesktop();
      }
      public function showDesktop():void
      {
          desktopScreen = new DesktopScreen();
          addChild( desktopScreen );
  
          stage.focus = desktopScreen;
      }
  }
  </code></pre>
  
  <p>And the relevant portion of <strong>DesktopScreen</strong>, the game's opening screen:</p>
  
  <pre><code>public class DesktopScreen extends MovieClip
  {
      public function DesktopScreen()
      {
          addEventListener( Event.ADDED_TO_STAGE, onAddtoStage );
      }
  
      public function onAddtoStage( e:Event ):void
      {
          Mouse.show();
  
          invisibleBG.alpha = 0;
          fakeButton.stop();
  
          time = new Time;
          time.x = 504;
          time.y = 3;
          addChild( time );
      }
  }
  </code></pre>
  
  <p><strong>TL;DR</strong> I'm adding a MovieClip to the stage, and even though I can tell via <code>trace</code> functions that it thinks it's on the stage, I can't see it or modify any of it's contents in a way that would require it to actually be on the stage.</p>