title: Action script - TypeError: Error #1009: Cannot access a property or method of a null object reference
body: <p>First am only been doing action script 2weeks and apologise for what appears To be a easy task for most. On timeline I've 2 frames the first frame just has a button to go to the next screen.The second screen has a 2 buttons to allow to go forward or backward 1 frame.</p>
  
  <p>I have 1 class file named main which am using for all the action script 
  the program works fine until I add the event listeners for the 2 buttons on the 2 frame then i get the the TypeError: </p>
  
  <blockquote>
    <p>Error #1009: Cannot access a property or method of a null object
    reference.\Desktop\weather\Main.as:17]</p>
  </blockquote>
  
  <p>Debug session terminated.</p>
  
  <p>Line 17 straight after the stop function </p>
  
  <pre><code>    package 
       {
  
      import flash.display.*;
      import flash.events.*;
  
  
      public class Main extends MovieClip
      {
  
  
          public function Main()
          {
              // constructor code
              Play_btn.addEventListener(MouseEvent.CLICK, playClicked);
              stop();
              back_btn.stage.addEventListener(MouseEvent.CLICK, backClicked);
              forward_btn.stage.addEventListener(MouseEvent.CLICK,forwardClicked);
  
  
          }
          function playClicked(evt:MouseEvent):void
          {
  
              nextFrame();
          }
          function backClicked(evt:MouseEvent):void
          {
              if (currentFrame == 1)
              {
                  gotoAndStop(totalFrames);
              }
              else
              {
                  prevFrame();
              }
          }
          function forwardClicked(evt:MouseEvent):void
          {
              if (currentFrame == totalFrames)
              {
                  gotoAndStop(1);
              }
              else
              {
                  nextFrame();
              }
          }
  
  
  
      }
  
  }
  /*
  back_btn.addEventListener(MouseEvent.CLICK, backClicked);
  forward_btn.addEventListener(MouseEvent.CLICK, forwardClicked);
  stop();
  
  function backClicked(evt:MouseEvent):void
  {
  if(currentFrame == 1)
  {
  gotoAndStop(totalFrames);
  }
  else
  {
  prevFrame();
  }
  }
  
  function forwardClicked(evt:MouseEvent):void
  {
  
  if(currentFrame == totalFrames)
  {
  gotoAndStop(1);
  }
  else
  {
  nextFrame();
  }
  }
  </code></pre>