I have been working off of a tutorial I found online, that has been teaching me to make a side scrolling game.

so far I have everything functioning just like the tutorial, and am looking to add a jump delay in between jumps...

the only problem is when ever i try to stick the reset for the jump timer, it makes the character freeze in midair and the jumping script gets all glitchy


can anyone take a peep and help me with this one?


Actionscript Code:
//LEVEL VARIABLES
//current row that we are creating
var row:int = 0;
//the current lvl
var lvlCurrent:int = 1;
/*The key for the level arrays:
1: Regular Block
2: Ladder
3: Bumper
X: Main Character
*/

//this variable will hold the character
var X:String = 'MAIN';
//the array for level 1
var lvlArray1:Array = new Array(
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,4,0,0,0,X,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
);

//whether or not main is on the ground
var mainOnGround:Boolean = false;
//These variables will note which keys are down
//We don't need the up or down key just yet
//but we will later
var leftKeyDown:Boolean = false;
var upKeyDown:Boolean = false;
var rightKeyDown:Boolean = false;
var downKeyDown:Boolean = false;
//the main character's speed
var mainSpeed:Number = 3;
//whether or not the main guy is jumping
var mainJumping:Boolean = false;
//how quickly should the jump start off
var jumpSpeedLimit:int = 12;
//the current speed of the jump;
var jumpSpeed:Number = jumpSpeedLimit;

//checking if the guy is on a ladder
var mainOnLadder:Boolean = false;

//BUMPING VARIABLES
//if main is being bumped
var mainBumping:Boolean = false;
//how quickly he should be bumped
var bumpSpeed:int = 20;
var jumpdelay:int = 0;

//adding a listener to mcMain which will make it move
//based on the key strokes that are down
mcMain.addEventListener(Event.ENTER_FRAME, moveChar);

function moveChar(event:Event):void{
    if (jumpdelay <=120){
    jumpdelay+=1;
        if(leftKeyDown){
        lvlHolder.x += mainSpeed;
    }
    if(rightKeyDown){
        lvlHolder.x -= mainSpeed;
    }
    }else{
            //if certain keys are down then move the character
    if(leftKeyDown){
        lvlHolder.x += mainSpeed;
    }
    if(rightKeyDown){
        lvlHolder.x -= mainSpeed;
    }
    if(upKeyDown || mainJumping){
        if(!mainOnLadder){
            mainJump();
                    }
    }
    if(upKeyDown && mainOnLadder){
        mcMain.y -= mainSpeed;
    }
    if(downKeyDown && mainOnLadder && !mainOnGround){
        mcMain.y += mainSpeed;
    }
    }
    //checking if he isn't on ground
    //run the loop checking if he's touching any blocks again
    for(var i:int = 0;i<blockHolder.numChildren; i++){
        //getting the current block
        var hitBlock:DisplayObject = blockHolder.getChildAt(i);
        //checking hit test and if main is above the brick
        if(mcMain.hitTestObject(hitBlock) && mcMain.y < hitBlock.y){
            //this time, we just make mainOnGround true
            mainOnGround = true;
            //and break from the loop
            break;
        }
        mainOnGround = false;
    }
   
    //hit testing for ladders
    for(i = 0;i<ladderHolder.numChildren;i++){
        //getting the current ladder
        var hitLadder:DisplayObject = ladderHolder.getChildAt(i);
        //checking hit test with the ladder
        if(mcMain.hitTestObject(hitLadder)){
                //checking if the guy is close enough
                if(mcMain.x >= hitLadder.x + lvlHolder.x - 10 && mcMain.x <= hitLadder.x + lvlHolder.x + 35){
                mainOnLadder = true;
                //reset the jump speed so he doesn't keep on jumping
                jumpSpeed = jumpSpeedLimit;
                break;
            }
        }
        mainOnLadder = false;
    }
    //hit testing for bumpers
    for(i=0;i<bumperHolder.numChildren;i++){
        //getting current bumper
        var hitBumper:DisplayObject=bumperHolder.getChildAt(i);
        //hit testing with the bumper
        if(mcMain.hitTestObject(hitBumper)){
            mainBumping = true;
            bumpSpeed = 20;
        }
    }
    //run mainBump
    mainBump();
    //hit testing trampolines
    for(i=0;i<trampHolder.numChildren;i++){
        //you know the drill
        var hitTramp:DisplayObject=trampHolder.getChildAt(i);
        if(mcMain.hitTestObject(hitTramp)){
            //just make him jump
            mainJump();
        }
    }
    //then we make him fall if he isn't on ground
    if(!mainOnGround){
        mainJumping = true;
    }
}

//listening for the keystrokes
//this listener will listen for down keystrokes
stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
function checkKeysDown(event:KeyboardEvent):void{
    //making the booleans true based on the keycode
    //WASD Keys or arrow keys
    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;
    }
}
//this listener will listen for keys being released
stage.addEventListener(KeyboardEvent.KEY_UP, checkKeysUp);
function checkKeysUp(event:KeyboardEvent):void{
    //making the booleans false based on the keycode
    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;
    }
}

//jumping function
function mainJump():void{
    //if main isn't already jumping
    if(!mainJumping){
        //then start jumping
        mainJumping = true;
        jumpSpeed = jumpSpeedLimit*-1;
        mcMain.y += jumpSpeed;
    } else {
        //then continue jumping if already in the air
        //crazy math that I won't explain
        if(jumpSpeed < 0){
            jumpSpeed *= 1 - jumpSpeedLimit/100;
            if(jumpSpeed > -jumpSpeedLimit/6){
                jumpSpeed *= -1;
            }
        }
        if(jumpSpeed > 0 && jumpSpeed <= jumpSpeedLimit){
            jumpSpeed *= 1 + jumpSpeedLimit/50;
        }
        mcMain.y += jumpSpeed;
                //if main hits a block, then stop jumping
        //this loop will check a hit test with any block
        for(var i:int = 0;i<blockHolder.numChildren; i++){
            //getting the current block
            var hitBlock:DisplayObject = blockHolder.getChildAt(i);
            //checking hit test
            if(mcMain.hitTestObject(hitBlock)){
                //if main is falling down
                if(jumpSpeed > 0){
                    //stop jumping
                    mainJumping = false;
                    //and set the guys coordinates to be on top of the block
                    mcMain.y = hitBlock.y - mcMain.height;
                    //he's on solid ground
                    mainOnGround = true;
                    //break out of the loop
                    break;
                } else {
                    jumpSpeed = Math.abs(jumpSpeed);
                    //making the main guy get away from the block
                    mcMain.y = hitBlock.y + hitBlock.height + 1;
                }
                }
               
        }
    }
}

//creating the level
var lvlHolder:Sprite = new Sprite();
addChild(lvlHolder);
//hold all trampolines
var trampHolder:Sprite = new Sprite();
lvlHolder.addChild(trampHolder);
//this guy will hold all of the blocks
var blockHolder:Sprite = new Sprite();
lvlHolder.addChild(blockHolder);
//this guy will hold all of the ladders
var ladderHolder:Sprite = new Sprite();
lvlHolder.addChild(ladderHolder);
//this guy wil hold all of the bumpers
var bumperHolder:Sprite = new Sprite();
lvlHolder.addChild(bumperHolder);
function createLvl():void{
    //getting the current level that we are on
    var lvlArray:Array = MovieClip(root)['lvlArray'+lvlCurrent];
    //we have to find how far this level goes
    //this will be used so we know when to move to the next row
    //there will always be 16 rows, so this is how we find it out
    //of course, this will make the lvl formatting very strict
    var lvlColumns:int = Math.ceil(lvlArray.length/16);
    //now we must create the level
    for(var i:int = 0;i<lvlArray.length;i++){
        //checking if we move onto the next row
        //this checks if i is divisible by the # of columns
        if(i/lvlColumns == int(i/lvlColumns)){
            row ++;
        }
        //defining a target
        var newPlacement;
        if(lvlArray[i] == 1){
            //making a new block
            newPlacement = new Block();
            //drawing the block
            newPlacement.graphics.beginFill(0xFFFFFF/*The color for shape*/,1/*The alpha for the shape*/);
            //turning the shape into a square
            newPlacement.graphics.drawRect(0,0,25,25);
            //then finally adding it to stage
            blockHolder.addChild(newPlacement);
        } else if (lvlArray[i] == 'MAIN'){
            newPlacement = mcMain;
        } else if (lvlArray[i] == 2){
            newPlacement = new Sprite();
            //drawing the ladder
            newPlacement.graphics.beginFill(0xFFFF00,1);
            //turning it into a square
            newPlacement.graphics.drawRect(0,0,25,25);
            //then adding it to stage
            ladderHolder.addChild(newPlacement);
        } else if (lvlArray[i] == 3){
            newPlacement = new Sprite();
            //drawing the bumper
            newPlacement.graphics.beginFill(0x00FF00,1);
            //turning it into a square
            newPlacement.graphics.drawRect(0,0,25,25);
            //then adding it to stage
            bumperHolder.addChild(newPlacement);
        } else if (lvlArray[i] == 4){
            newPlacement = new Shape();
            newPlacement.graphics.beginFill(0x00FF00);
            newPlacement.graphics.drawCircle(12.5,25,12.5);
            trampHolder.addChild(newPlacement);
        }
       
        if(lvlArray[i] != 0){
            //change the coordinates of the block
            newPlacement.x = (i-(row-1)*lvlColumns)*newPlacement.width;
            newPlacement.y = (row-1)*newPlacement.height;
        }
    }
    //reset the row for another use
    row = 0;
    //then we center the screen on the main character
    //this variable will tell us how far away we have to move everything
    //250 is about centered for mcMain we'll use that number
    var mainMove:int = 250 - mcMain.x;
    //then move mcMain and the entire level to center on him
    mcMain.x += mainMove;
    lvlHolder.x += mainMove;
}

//bumping function
function mainBump():void{
    //testing the direction of bump
    var bumpDirection:int;
    if(leftKeyDown){
        bumpDirection = 1;
    } else if (rightKeyDown){
        bumpDirection = -1;
    }
    if(mainBumping){
        lvlHolder.x -= bumpDirection*bumpSpeed;
        bumpSpeed *= .5;
        if(bumpSpeed <= 1){
            mainBumping = false;
        }
    }
}

//running the createlvl funciton
createLvl();
//placing the guy on top
MovieClip(root).setChildIndex(mcMain,MovieClip(root).numChildren-1);