title: How do I stop a sprite from jumping in midair? ActionScript 3/Flash Pro CC 2015
body: <p>I am a beginner Flash/AS3 programmer and I have a very sophisticated problem. How can I prevent a sprite from jumping in midair? I've seen the other question related to &quot;sprite/jump in midair&quot;, but I personally cannot figure out how to do that in AS3. Thank you for any response.
  Code:</p>
  <pre><code>public class DocumentMain extends MovieClip {
      private var _vx: Number;
      import flash.utils.Timer;
      import flash.ui.Keyboard;
      import flash.events.Event;
      import flash.events.KeyboardEvent;
      private var _vy: Number;
      public function DocumentMain() {
          // constructor code
          _vx = 0;
          _vy = 0
          _startMarker.visible = false;
          this.addEventListener(&quot;enterFrame&quot;, a);
          stage.addEventListener(&quot;keyDown&quot;, b);
          stage.addEventListener(&quot;keyUp&quot;, c);
          _windows.addEventListener(&quot;enterFrame&quot;, handleCollision);
          
          function handleCollision( e:Event ):void
          {
          {
                  var collisionWall:Boolean = false;
                  if (wall.hitTestObject(_windows)) {
                      collisionWall = true;
                  }
                  if (collisionWall) {
                      while (collisionWall) {
                          _windows.x += 0.1; 
                          collisionWall = false;
                          if (wall.hitTestObject(_windows)) {
                          collisionWall = true;
                           }
                      }
                      _vx = 0;
                  }
          }
      }
          function a(e:Event):void {
              _vy += 2;
              _windows.x += _vx;
              _windows.y += _vy;
              
              
              if (_vy &gt; 0) {
                  if (_windows.y &gt; stage.stageHeight) {
                      _windows.x = _startMarker.x;
                      _windows.y = _startMarker.y;
                      _vy = 0;
                  }
                  
              else {
                  var collision:Boolean = false;
                  if (ground.hitTestObject(_windows)) {
                      collision = true;
                  }
                  if (collision) {
                      while (collision) {
                          _windows.y -= 0.1; 
                          collision = false;
                          if (ground.hitTestObject(_windows)) {
                          collision = true;
                           }
                      }
                      _vy = 0;
                  }
                  
              }
          }
      
      }
          
          function b(e:KeyboardEvent):void {
              var step:uint = 5
                switch (e.keyCode) {
                    case 37:
                        _windows.rotationY = -180;
                        _vx = -7;
                    break;
                    
                    case 39:
                        _windows.rotationY = 0;
                        _vx = 7;
                    break;
                    
                      case 38:
                       
                        _vy = -20;
                        break;
                                  
                        
  
                  }
          } 
          
          function c(e:KeyboardEvent):void {
              switch (e.keyCode) {
                  case 37:
                  case 39:
                      _vx = 0;
              }
              
          }
  
      }
  }
  </code></pre>