title: AS3 - Error 1119 - Access of possibly undefined property y through a reference with static type Class
body: <p>So I've searched through this site and a few others pertaining the error code 1119, and none of them really helped me figure out what was wrong.  Essentially, the same error comes up 2 times for 4 different pieces of code that are also very similar to each other.  They are simply the codes needed to move an object in flash a certain number of units.  Here's all of the code:</p>
  
  <pre><code>package
  {
      import flash.display.MovieClip;
      import flash.events.Event;
      import flash.events.KeyboardEvent;
  
      public class Work extends MovieClip
      {
          var touching:Boolean = false;
  
          public function Work()
          {
              startGame();
          }
          function startGame():void
          {
              stage.addEventListener(Event.ENTER_FRAME, gameLoop);
              stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
          }
          function gameLoop(event:Event):void
          {
              checkCollisions();
          }
          function keyDownHandler(keyEvent:KeyboardEvent):void
          {
              if (keyEvent.keyCode == 40) 
              {
                  flyer.y += 10; 
                  }
              else if (keyEvent.keyCode == 39) {
                  flyer.x += 10; 
                  }
              else if (keyEvent.keyCode == 37) {
                  flyer.x -= 10; 
                  }
              else if (keyEvent.keyCode == 38) {
                  flyer.y -= 10; 
              }
          }
  
          function checkCollisions()
          {
              if (flyer.hitTestObject(square))
              {
                  touching = true;
              }
              else
              {
                  touching = false;
              }
          }
      }
  }
  </code></pre>
  
  <p>(I don't know why the first parts are excluded from the coding box, but oh well.  I couldn't manually indent because Tab button changes selection on my web page)</p>
  
  <p>Now, here is the exact piece of code where it's giving me the errors:</p>
  
  <pre><code>function keyDownHandler(keyEvent:KeyboardEvent):void {
  
      if (keyEvent.keyCode == 40) {
          flyer.y += 10; 
      }
      else if (keyEvent.keyCode == 39) {
          flyer.x += 10; 
      }
      else if (keyEvent.keyCode == 37) {
          flyer.x -= 10; 
      }
      else if (keyEvent.keyCode == 38) {
          flyer.y -= 10; 
      }
  </code></pre>
  
  <p>(again, text buggin' out on me)
  Now, it's not just givving the 1119 error on one of these, but ALL of them, TWICE!  Here, let me show you:</p>
  
  <p><img src="https://i.stack.imgur.com/2s9zT.png" alt="example"></p>
  
  <p>Another thing to add onto this plea for help, is the last error you see at the bottom of the errors list.  It also baffles me, error 1061.  It says that <code>hitTestObject</code> is an undefined method, yet not only have I used it before, but I see it used all the time!
  I really don't know why I'm getting these errors, why they're popping up twice, or how to fix them.  Some assistance would be much appreciated!</p>