Ive written this for a platformer Im making- its really just for the jumping physics now, and ive been trying to prevent that hopping that happens if you land and are still holding the up button. While i got that to work, this weird little thing happens when you jump, you can mash the up key to slow down your falling speed. Why the heck would that happen?- it should be set up so nothing at all happens when the jump key is hit and the hero isnt both grounded and canJump.

package
{
import flash.display.MovieClip;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event;

public class Main extends MovieClip
{
public var vx:Number;
public var vy:Number;
public var gravity:Number;
public var canJump:Boolean;
public var grounded:Boolean;

public function Main()
{
vx = 0;
vy = 0;
gravity = .7;
canJump = true;
grounded = false;

stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
public function onKeyDown(event:KeyboardEvent):void
{
if (event.keyCode == Keyboard.LEFT)
{
vx = -5;
}
else if (event.keyCode == Keyboard.RIGHT)
{
vx = 5;
}
else if (event.keyCode == Keyboard.UP && canJump && grounded)
{
vy -= 10;
canJump = false;
grounded = false;
}
}
public function onKeyUp(event:KeyboardEvent):void
{
if (event.keyCode == Keyboard.LEFT || event.keyCode == Keyboard.RIGHT)
{
vx = 0;
}
if (event.keyCode == Keyboard.UP)
{
vy = 0;
canJump = true;
}
}
public function onEnterFrame(event:Event):void
{
vy += gravity;
hero.x += vx;
hero.y += vy;

if (hero.y > 320)
{
vy = 0;
hero.y = 320;
grounded = true;
}
//trace(canJump);
//trace(grounded);
}
}
}