title: Flash AS3 Access Global Variables From A MovieClip
body: <p>I have a movie clip of an explosion which is done in code because I am randomizing the direction and amount of debris from the explosion, so it's a movie clip with one frame, and all animation is done in code. Problem is, I'm trying to pause the game from the main timeline when the player presses "p". Right now I have it so it turns the variable gamePaused = true and calls the function pauseGame() which stops everything else. However I don't know how to access the variable gamePaused from inside the explosion movie clip's code. If I can somehow check that variable in the movie clip, I can pause that animation until the player presses "p" again.</p>
  
  <p>So basically, how do I access a variable in the main timeline from a movie clip?</p>
  
  <p>Also just to point out, all of these explosions were created as Sprites in the main timeline's code, any solutions I have found online didn't like that. So just keep that in mind.</p>
  
  <p>Here's the main timeline code:</p>
  
  <pre><code>//This Creates An Explosion&lt;br&gt;
  function createExplosion(explosionX, explosionY, explosionSize):void{&lt;br&gt;
      //This Creates The Explosion Movie Clip
      var explosionSprite:Sprite = new Sprite;
      addChild(explosionSprite);
      var explosionPic:explosionSym = new explosionSym;
      explosionSprite.addChild(explosionPic);&lt;br&gt;
  &lt;br&gt;
      //This Moves It Into Position
      if (explosionSize == 3){&lt;br&gt;
          explosionSprite.x = explosionX + 15;&lt;br&gt;
          explosionSprite.y = explosionY + 15;&lt;br&gt;
      }&lt;br&gt;
      else if (explosionSize == 2){&lt;br&gt;
          explosionSprite.x = explosionX + 5;&lt;br&gt;
          explosionSprite.y = explosionY + 5;&lt;br&gt;
      }&lt;br&gt;
      else if (explosionSize == 1){&lt;br&gt;
          explosionSprite.x = explosionX;&lt;br&gt;
          explosionSprite.y = explosionY;&lt;br&gt;
      }&lt;br&gt;
      &lt;br&gt;
      //This Starts The Timer
      explosion[explosionsOnScreen] = explosionSprite;
      explosionTimeLeft[explosionsOnScreen] = 0;
  }
  //This Removes The Explosions Once Time Is Up
  function explosionTimer(evt:TimerEvent):void{
      //This Declares The Variables
      var M:int = 0;
  
      for (M = 0; M &lt; explosionsOnScreen; M++){
          //This Increments The Time
          explosionTimeLeft[M]++;
  
          //This Removes The Explosion If Enough Time Has Passed
          if (explosionTimeLeft[M] &gt; 15){
              explosion[M].parent.removeChild(explosion[M]);
              explosion.splice(M, 1);
              explosionTimeLeft.splice(M, 1);
              explosionsOnScreen -= 1;
              break;
          }
      }
  }
  
  //This Creates Bullets To Be Used As Debris
  function spawnBullets():void{&lt;br&gt;
      //This Declares The Variables&lt;br&gt;
      var M:int = 0;&lt;br&gt;
  
      //This Decides How Much Debris Will Appear
      randomDebrisNumber = (Math.round(Math.random() * 3) + 3);
  
      for (M = 0; M &lt;= randomDebrisNumber; M++){
          //This Spawns The Bullets
          var debrisSprite:Sprite = new Sprite;
          addChild(debrisSprite);
          var debrisBullet:bulletSym = new bulletSym;
          debrisSprite.addChild(debrisBullet);
  
          //This Places The Debris
          debrisSprite.x = 0;
          debrisSprite.y = 0;
  
          //This Adds The Sprite To The Array
          debris[M] = debrisSprite;
  
          //This Gets The Direction It Moves
          do {
              debrisX[M] = ((Math.random() * 2 - 1) * 3);
              debrisY[M] = ((Math.random() * 2 - 1) * 3);
          } while ((debrisX[M] &gt; -0.1 &amp;&amp; debrisX[M] &lt; 0.1) || (debrisY[M] &gt; -0.1 &amp;&amp; debrisY[M] &lt; 0.1))
      }
  }
  
  //This Moves The Debris Away From The Center
  function handleMoveDebris(evt:TimerEvent):void{&lt;br&gt;
      //This Declares The Variables&lt;br&gt;
      var M:int = 0;&lt;br&gt;
  
      //This Increments The Timer
      debrisTimerCount++;
  
      if (debrisTimerCount &lt;= 15){
          //This Moves The Debris
          for (M = 0; M &lt;= randomDebrisNumber; M++){
              debris[M].x += debrisX[M];
              debris[M].y += debrisY[M];
          }
      }
      else if (debrisTimerCount &gt; 15){
          //This Removes the Debris
          for (M = randomDebrisNumber; M &gt;= 0; M--){
              debris[M].parent.removeChild(debris[M]);
              debris.splice(M, 1);
              debrisX.splice(M, 1);
              debrisY.splice(M, 1);
          }
  
          //This Stops The Timer
          debrisTimerCount = 0;
          timMoveDebris.stop();
      }
  }
  </code></pre>