title: Stop character on Platform with collision when falling: AS3
body: <p>I am making a platform game. At the moment I am just trying to create gravity, and platforms. I've got the gravity down pat, but when my character (player) collides with the platform, he instantly appears back at the top of the screen and falls down again, and it just keeps repeating each time the player touches the platform. Here's my code:</p>
  
  <pre><code>package  {
  
  import flash.display.MovieClip;
  import flash.events.KeyboardEvent;
  import flash.events.Event;
  import flash.ui.Keyboard;
  
  
  public class GameCode extends MovieClip {
  
      var upKey:Boolean;
      var leftKey:Boolean;
      var rightKey:Boolean;
      var jump:Boolean = false;
  
      var xvelocity:int = 10;
      var yvelocity:int = 0;
      var gravity:Number = 7;
  
      var startPosY:int;
      var startPosX:int;
      var lastPosY:int;
      var lastPosX:int;
  
      public function GameCode() {
          // constructor code
      }
  
      public function startGame(){
          stage.addEventListener(KeyboardEvent.KEY_UP, checkKeyUp);
          stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeyDown);
          stage.addEventListener(Event.ENTER_FRAME, update);
      }
  
      function update(evt:Event){
          moveCharacter();
          yvelocity += gravity;
  
          for (var i:int = 0; i &lt; 10; i++){
              if (!platform.hitTestObject(player)){
                  player.y = yvelocity;
              }
              if (platform.hitTestObject(player)){
                  yvelocity = 0;
                  player.y--;
              }
          }
      }
  
      function moveCharacter(){
          lastPosY = player.y;
          lastPosX = player.x;
  
          if (leftKey == true){
              player.x -= xvelocity;
          }
          if (rightKey == true){
              player.x += xvelocity;
          }
          if (upKey == true){
              if (jump == true){
                  player.y
              }
          }
      }
  
      function checkKeyDown(evt:KeyboardEvent){
          if (evt.keyCode == Keyboard.LEFT){
              leftKey = true;
          }
          else if (evt.keyCode == Keyboard.RIGHT){
              rightKey = true;
          }
          else if (evt.keyCode == Keyboard.UP){
              upKey = true;
          }
      }
  
      function checkKeyUp(evt:KeyboardEvent){
          if (evt.keyCode == Keyboard.LEFT){
              leftKey = false;
          }
          else if (evt.keyCode == Keyboard.RIGHT){
              rightKey = false;
          }
          else if (evt.keyCode == Keyboard.UP){
              upKey = false;
          }
      }
  }
  
  }
  </code></pre>
  
  <p>My character's instance name is player and my platforms instance is simply just platform.
  Obviously, I would like help on how to change this; What I want is for the character to fall with gravity, land on the platform, be able to move around, and when falling off the character falls off to the bottom.</p>