title: Use variables from one .as file in another?
body: <p>If I have created variables in one document named Main.as as follows:</p>
  
  <pre><code>var backgroundLayer:Sprite = new Sprite;
  var gameLayer:Sprite = new Sprite;
  var interfaceLayer:Sprite = new Sprite;
  </code></pre>
  
  <p>How can I access these in another .as file? I'm trying to sort the objects in my game into layers but I'm getting errors. For example, I have a EnemyShip.as file with the following in it:</p>
  
  <pre><code>function enterFrame(e:Event)
          {
              this.x -= speed;
              if(this.x &lt; -100)
              {
                  removeEventListener("enterFrame", enterFrame);
                  stage.removeChild(this);
              }
          }
  
  function kill()
          {
              var explosion = new Explosion();
              stage.addChild(explosion);
              explosion.x = this.x;
              explosion.y = this.y;
              removeEventListener("enterFrame", enterFrame);
              stage.removeChild(this);
              Main.updateScore(1);
              shot.play();
          }
  </code></pre>
  
  <p>The problem is I was trying to change <code>stage.addChild(explosion)</code> to <code>gameLayer.addChild(explosion)</code> but I got an <code>access of undefined property gameLayer</code> error. </p>
  
  <p>There may be something obvious I am missing, so please let me know. I'm also not too sure whether I should be using <code>new Sprite</code> or <code>new Movieclip</code>; the majority of my game is made up of movie clips and buttons, so perhaps this should be changed?</p>
  
  <p>Thanks.</p>
  
  <p>EDIT: I tried Kodiak's second solution by doing the following (Relevant parts):</p>
  
  <p>EnemyShip.as:</p>
  
  <pre><code>package
  {
  import flash.display.MovieClip;
  import flash.events.Event;
  import flash.events.MouseEvent;
  import flash.events.TimerEvent;
  import flash.utils.Timer;
  import flash.ui.Mouse;
  import flash.media.Sound;
  import flash.media.SoundChannel;
  import flash.text.TextFormat;
  import flash.text.TextField;
  import flash.display.Loader;
  import flash.net.URLRequest;
  import flash.net.URLLoader;
  import flash.system.LoaderContext;
  import flash.display.Sprite;
  import flash.net.Socket;
  
  public class EnemyShip extends MovieClip
  {
      public static var gameLayer:Sprite;
  
      var speed:Number;
      var shot = new ShotSound();
  
      public function EnemyShip()
      {
          this.x = 800;
          this.y = Math.random() * 275 + 75;
          speed = Math.random()*5 + 9;
          addEventListener("enterFrame", enterFrame);
          addEventListener(MouseEvent.MOUSE_DOWN, mouseShoot);
      }
  </code></pre>
  
  <p>Main.as:</p>
  
  <pre><code>package  {
   import flash.display.MovieClip;
   import flash.display.Sprite;
   import flash.display.DisplayObject;
  import flash.events.Event;
  import flash.events.MouseEvent;
  import flash.events.TimerEvent;
  import flash.utils.Timer;
  import flash.ui.Mouse;
  import flash.media.Sound;
  import flash.media.SoundChannel;
  import flash.text.TextFormat;
  import flash.text.TextField;
  import flash.display.Loader;
  import flash.net.URLRequest;
  import flash.net.URLLoader;
  import flash.system.LoaderContext;
  import flash.display.Sprite;
  import flash.net.Socket;
  
  
  public class Main extends MovieClip {
  
  EnemyShip.gameLayer = gameLayer;
  var interfaceLayer:Sprite = new Sprite;
  var menuLayer:Sprite = new Sprite;
  var endGameLayer:Sprite = new Sprite;
  </code></pre>
  
  <p>I'm getting errors like <code>1120: Access of undefined property gameLayer</code> on lines such as <code>EnemyShip.gameLayer = gameLayer;</code> and when I try to do things like:</p>
  
  <pre><code>    crosshair = new crosshair_mc();
      gameLayer.addChild(crosshair);
  </code></pre>
  
  <p>I get the same error.</p>