title: AS3 Restrict ship in visible stage area
body: <p>Hey so i've been making a space shooter game and i created the movement but i'm trying to restricting the ship to the visible stage area and i can't figure out how to do that</p>
  <p>also i'm sorry if my code it's really messy i'm really new at this</p>
  <p>the stage size it's 1920 x 1080</p>
  <p>here's the code of the movement</p>
  <pre><code>var leftKeyPressed: Boolean = false;
  var rightKeyPressed: Boolean = false;
  var upKeyPressed: Boolean = false;
  var downKeyPressed: Boolean = false;
  
  var xMoveSpeed: Number = 15;
  var yMoveSpeed: Number = 15;
  
  stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
  
  function keyDownHandler(e: KeyboardEvent): void
  {
      if (e.keyCode == Keyboard.LEFT)
      {
          leftKeyPressed = true;
  
      }
      if (e.keyCode == Keyboard.RIGHT)
      {
          rightKeyPressed = true;
  
      }
      if (e.keyCode == Keyboard.UP)
      {
          upKeyPressed = true;
  
      }
      if (e.keyCode == Keyboard.DOWN)
      {
          downKeyPressed = true;
  
      }
  }
  
  stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
  
  function keyUpHandler(e: KeyboardEvent): void
  {
      if (e.keyCode == Keyboard.LEFT)
      {
      leftKeyPressed = false;
      }
      if (e.keyCode == Keyboard.RIGHT)
      {
          rightKeyPressed = false;
      }
      if (e.keyCode == Keyboard.UP)
      {
          upKeyPressed = false;
      }
      if (e.keyCode == Keyboard.DOWN)
      {
          downKeyPressed = false;
      }
  }
  
  stage.addEventListener(Event.ENTER_FRAME, moveHero);
  
  function moveHero(e: Event): void
  {
      if (leftKeyPressed)
      {
          ship.x -= xMoveSpeed;
      }
      if (rightKeyPressed)
      {
          ship.x += xMoveSpeed;
      }
      if (upKeyPressed)
      {
          ship.y -= yMoveSpeed;
      }
      if (downKeyPressed)
      {
          ship.y += yMoveSpeed;
      }
  } 
  </code></pre>