Gravity Help

[FONT=courier new]I haven’t been on kirupa in a while. Just been looking at flash, mostly.
Anyway, I have took up a huge project. I can’t find classes so I’m self-taught. I Googled a good Platforming tutorial in as3 and it works fine. But I want to put the code on my person, so I started doing that.

When I try to jump, if I let go too early, he stays in mid-air. This wasn’t a problem when it was on the main timeline, but it is now.

So can you help me add some gravity into this code?
It’s a bit long, so don’t lose me here:


var leftKeyDown:Boolean = false;
var upKeyDown:Boolean = false;
var rightKeyDown:Boolean = false;
var downKeyDown:Boolean = false;
var mainSpeed:Number = 7;
this.gotoAndStop(1); 
this.addEventListener(Event.ENTER_FRAME, moveChar);
function moveChar(event:Event):void{
    if(leftKeyDown){
        this.x -= mainSpeed;
        this.gotoAndStop(3);
    }
    if(rightKeyDown){
        this.x += mainSpeed;
        this.gotoAndStop(3);
    }
    if(upKeyDown || mainJumping){
        mainJump();
        this.gotoAndStop(2);
    }
    if(!leftKeyDown && !rightKeyDown && !upKeyDown){
        this.gotoAndStop(1);
        if(mainJumping){
            this.gotoAndStop(2);
        }
    }
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
function checkKeysDown(event:KeyboardEvent):void{
    if(event.keyCode == 37 || event.keyCode == 65){
        leftKeyDown = true;
    }
    if(event.keyCode == 38 || event.keyCode == 87){
        upKeyDown = true;
    }
    if(event.keyCode == 39 || event.keyCode == 68){
        rightKeyDown = true;
    }
    if(event.keyCode == 40 || event.keyCode == 83){
        downKeyDown = true;
    }
}
stage.addEventListener(KeyboardEvent.KEY_UP, checkKeysUp);
function checkKeysUp(event:KeyboardEvent):void{
    if(event.keyCode == 37 || event.keyCode == 65){
        leftKeyDown = false;
    }
    if(event.keyCode == 38 || event.keyCode == 87){
        upKeyDown = false;
    }
    if(event.keyCode == 39 || event.keyCode == 68){
        rightKeyDown = false;
    }
    if(event.keyCode == 40 || event.keyCode == 83){
        downKeyDown = false;
    }
}
var mainJumping:Boolean = false;
var jumpSpeedLimit:int = 15;
var jumpSpeed:Number = jumpSpeedLimit;
function mainJump():void{
    if(!mainJumping){
        mainJumping = true;
        jumpSpeed = jumpSpeedLimit*-1;
        this.y += jumpSpeed;
    } else {
        if(jumpSpeed < 0){
            jumpSpeed *= 1 - jumpSpeedLimit/75;
            if(jumpSpeed > -jumpSpeedLimit/5){
                jumpSpeed *= -1;
            }
        }
        if(jumpSpeed > 0 && jumpSpeed <= jumpSpeedLimit){
            jumpSpeed *= 1 + jumpSpeedLimit/50;
        }
        this.y += jumpSpeed;
        if(this.y >= stage.stageHeight - this.height){
            mainJumping = false;
            this.y = stage.stageHeight - this.height;
            this.gotoAndStop(1);
        }
    }
}

[/FONT][FONT=courier new]

I think the problem comes more towards the end.
Frame 1 is standing still.
Frame 2 is moving left & right. I made an internal movie clip of a walking loop, so when you freeze on the frame it looks like walking.
Frame 3 is jumping.

Remember, this code is inside the person.

Help?

-FlashAj325
[/FONT]