Need help with 2d platformer

Hi , I’ve been having some trouble with a 2d platform game that I’ve been working on for the past week. I used some code from a few tutorials and have basic left and right movement and some collisions. My main problem is that when i jump on a block and walk off it the player doesn’t fall. Here is my code. I’m using actionscript 3.0 in flash cs3.
Here’s the code from my as file, sorry if its a little long.


package 
{
    import flash.display.MovieClip;
    import flash.display.*;
    import flash.events.*;
    import flash.events.MouseEvent;
    import flash.media.Sound;

    //needed to add this in to make the dynamic textfield on stage work
    import flash.text.TextField;

    public class MainStart extends MovieClip
    {
        var leftKeyDown:Boolean;
        var upKeyDown:Boolean;
        var rightKeyDown:Boolean;
        var downKeyDown:Boolean;

        var mainOnGround:Boolean = false;

        //============================
        //the main character's speed
        //============================
        var mainSpeed:Number;

        //=======================================
        //whether or not the main guy is jumping
        //=======================================
        var mainJumping:Boolean;

        //=======================================
        //how quickly should the jump start off
        //=======================================
        var jumpSpeedLimit:int;

        //================================
        //the current speed of the jump;
        //================================
        var jumpSpeed:Number;

        //=================================
        // declares player movieclip var
        //=================================
        var mcMain:MovieClip;

        var background1:MovieClip;
        var background2:MovieClip;
        var background3:MovieClip;
        //=================================
        // declares level movieclip var
        //=================================
        var gamelevel:MovieClip;

        var blockcount:Number = 0;
        var platformcount:Number = 0;

        var thenum:Number = 0;

        private var fixedObjects:Array;
        private var rotating_platforms:Array;

        public function MainStart()
        {

            init();
        }
        function randNum(minNum:Number, maxNum:Number):Number
        {
            return Math.round(Math.random() * maxNum - minNum) + minNum;
        }
        function init():void
        {

            leftKeyDown = false;
            upKeyDown = false;
            rightKeyDown = false;
            downKeyDown = false;

            mainSpeed = 7;

            mainJumping = false;

            jumpSpeedLimit = 15;

            jumpSpeed = 0;

            background3 = new lvl1bkgd3();
            background3.x = 0;
            background3.y = 0;
            addChild(background3);

            background2 = new lvl1bkgd2();
            background2.x = -600;
            background2.y = 0;
            addChild(background2);

            background1 = new lvl1bkgd1();
            background1.x = -800;
            background1.y = -150;//471;
            addChild(background1);

            gamelevel = new myFirstLevel();
            gamelevel.x = 0;
            gamelevel.y = 0;
            addChild(gamelevel);

            mcMain = new mcPlayer();
            mcMain.x = 446;
            mcMain.y = 360;
            addChild(mcMain);

            examineLevel();

            trace(fixedObjects[0].topside);

            trace(gamelevel.x);


            mcMain.addEventListener(Event.ENTER_FRAME, moveChar);


            stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);


            stage.addEventListener(KeyboardEvent.KEY_UP, checkKeysUp);

        }

        //------------------------------------------------------------
        // Function: examineLevel
        // this function loads all level objects into arrays
        //------------------------------------------------------------
        public function examineLevel()
        {
            fixedObjects = new Array();
            rotating_platforms = new Array();

            for (var i:int=0; i<this.gamelevel.numChildren; i++)
            {
                var mc = this.gamelevel.getChildAt(i);

                // add bricks and platforms to fixedObjects
                if ((mc is bricks) || (mc is platform))
                {
                    var floorObject:Object = new Object();

                    blockcount = blockcount + 1;

                    floorObject.mc = mc;
                    floorObject.leftside = mc.x;
                    floorObject.rightside = mc.x+mc.width;
                    floorObject.topside = mc.y;
                    floorObject.bottomside = mc.y+mc.height;

                    trace("block#",blockcount, "x:",mc.x, " y:", mc.y);
                    fixedObjects.push(floorObject);
                }
            }
            for (var i:int=0; i<this.gamelevel.numChildren; i++)
            {
                var mc = this.gamelevel.getChildAt(i);
                // add rotating_platform to fixedObjects
                if (mc is a_rotating_platform)
                {
                    var rotatingObject:Object = new Object();
                    platformcount = platformcount + 1;
                    rotatingObject.mc = mc;
                    trace("platform#",platformcount, "x:",rotatingObject.mc.x, " y:", rotatingObject.mc.y);

                    rotating_platforms.push(rotatingObject);
                }
            }
        }
        //----------------------------------------------------------------------------------------------------
        // Function: moveChar
        //----------------------------------------------------------------------------------------------------
        function moveChar(event:Event):void
        {
            if (leftKeyDown)
            {
                //trace(mainSpeed);
                mcMain.x -= mainSpeed;
                mcMain.scaleX = 1;
            }
            if (rightKeyDown)
            {
                mcMain.x += mainSpeed;
                mcMain.scaleX = -1;
            }
            if (upKeyDown || mainJumping)
            {

                mainJump();
            }
            thenum = thenum + 1;

            //--------------------------------------------------
            // this code rotates the platforms
            //--------------------------------------------------
            for (var i:int = 0; i<rotating_platforms.length; i++)
            {
                rotating_platforms*.mc.rotate0.topside = rotating_platforms*.mc.rotate0.y + rotating_platforms*.mc.y ;
                rotating_platforms*.mc.rotate0.bottomside = rotating_platforms*.mc.rotate0.y + rotating_platforms*.mc.rotate0.height  + rotating_platforms*.mc.y;

                rotating_platforms*.mc.theBlock.topside = rotating_platforms*.mc.theBlock.y;
                rotating_platforms*.mc.theBlock.bottomside = rotating_platforms*.mc.theBlock.y + rotating_platforms*.mc.theBlock.height;
                rotating_platforms*.mc.theBlock.leftside = rotating_platforms*.mc.theBlock.x - rotating_platforms*.mc.theBlock.width / 2;
                rotating_platforms*.mc.theBlock.rightside = rotating_platforms*.mc.theBlock.x + rotating_platforms*.mc.theBlock.width / 2;

                rotating_platforms*.mc.rotate0.y = 208 * Math.sin(.05 * thenum) ;
                rotating_platforms*.mc.rotate0.x = 208 * Math.cos(.05 * thenum) ;

                rotating_platforms*.mc.rotate1.y = 192 * Math.sin(.05 * thenum) ;
                rotating_platforms*.mc.rotate1.x = 192 * Math.cos(.05 * thenum) ;

                rotating_platforms*.mc.rotate2.y = 160 * Math.sin(.05 * thenum) ;
                rotating_platforms*.mc.rotate2.x = 160 * Math.cos(.05 * thenum) ;

                rotating_platforms*.mc.rotate3.y = 128 * Math.sin(.05 * thenum) ;
                rotating_platforms*.mc.rotate3.x = 128 * Math.cos(.05 * thenum) ;

                rotating_platforms*.mc.rotate4.y = 96 * Math.sin(.05 * thenum) ;
                rotating_platforms*.mc.rotate4.x = 96 * Math.cos(.05 * thenum) ;

                rotating_platforms*.mc.rotate5.y = 64 * Math.sin(.05 * thenum) ;
                rotating_platforms*.mc.rotate5.x = 64 * Math.cos(.05 * thenum) ;

                rotating_platforms*.mc.rotate6.y = 32 * Math.sin(.05 * thenum) ;
                rotating_platforms*.mc.rotate6.x = 32 * Math.cos(.05 * thenum) ;

            }
            for (var i:int = 0; i<fixedObjects.length; i++)
            {
                var hitBlock = fixedObjects*;

                if (mcMain.hitTestObject(hitBlock.mc) && mcMain.x  -gamelevel.x  < hitBlock.leftside)
                {
                    trace("leftside collision");
                    mcMain.x = (hitBlock.leftside - (mcMain.width / 2))+gamelevel.x - 1;
                }
                if (mcMain.hitTestObject(hitBlock.mc) && mcMain.x -gamelevel.x > hitBlock.rightside)
                {
                    trace("rightside collision");
                    mcMain.x = (hitBlock.rightside + (mcMain.width / 2))+gamelevel.x + 1;
                }
            }
            //============================================================
            // check collisions for rotating_platforms
            //============================================================
            for (var i:int = 0; i<rotating_platforms.length; i++)
            {
                var hitBlock = rotating_platforms*.mc.rotate0;


                //trace(hitBlock.mc.x + "  " + hitBlock.mc.y)
                if (mcMain.hitTestObject(hitBlock) && mcMain.y < hitBlock.topside)
                {
                    trace("TOP1");
                    mainOnGround = false;

                    mainJumping = false;
                    
                    mcMain.y = hitBlock.topside - mcMain.height/2;// - 1;
                    //break;
                }
                if (mcMain.hitTestObject(hitBlock) && mcMain.y > hitBlock.bottomside)
                {
                    trace("BOTTOM1");
                    mainOnGround = false;

                    mainJumping = false;
                    
                    mcMain.y = hitBlock.bottomside + mcMain.height/2;// + 1;

                    
                }
            }
            


            for (var i:int = 0; i<fixedObjects.length; i++)
            {
                var hitBlock = fixedObjects*;
                if (mcMain.hitTestObject(hitBlock.mc) && mcMain.y < hitBlock.mc.y)
                {
                    mainOnGround = true;
                    break;
                }
                mainOnGround = false;
            }

            if (!mainOnGround)
            {
                //mainJumping = true;
            }
            scroll();
        }



        //----------------------------------------------------------------------------------------------------
        // Function: scroll
        //----------------------------------------------------------------------------------------------------
        public function scroll():void
        {
            var rightEdge:Number = 500;
            var leftEdge:Number = 100;
            if ((mcMain.x > rightEdge) && (gamelevel.x > (-gamelevel.width + stage.stageWidth)))
            {

                mcMain.x = rightEdge;

                gamelevel.x += -mainSpeed;


                background1.x += .66 * -mainSpeed;
                if (background1.x < -1600)
                {
                    background1.x = -800;
                    trace("just reset background1 position");
                }
                background2.x += .33 * -mainSpeed;
                if (background2.x < -1200)
                {
                    background2.x = -600;
                }
                background3.x += 0 * -mainSpeed;
                if (background3.x < -1200)
                {
                    background3.x = -600;
                }
                if (gamelevel.x < (-1*(gamelevel.width - stage.stageWidth)))
                {
                    gamelevel.x = (-1*(gamelevel.width - stage.stageWidth));
                    //trace("gamelevel.x " + gamelevel.x);
                }
            }
            if ((mcMain.x < leftEdge) && (gamelevel.x < 0))
            {
                mcMain.x = leftEdge;
                gamelevel.x += mainSpeed;

                background1.x += .66 * mainSpeed;
                if (background1.x > 0)
                {
                    background1.x = -800;
                    trace("just reset background1 position");
                }
                background2.x += .33 * mainSpeed;
                if (background2.x > 0)
                {
                    background2.x = -600;
                }
                background3.x += 0 * mainSpeed;
                if (background3.x > 0)
                {
                    background3.x = -600;
                }
                if (gamelevel.x > 0)
                {
                    gamelevel.x = 0;
                }
            }
        }

        //----------------------------------------------------------------------------------------------------
        // Function: 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;
            }
        }


        //----------------------------------------------------------------------------------------------------
        // Function: 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;
            }
        }


        //----------------------------------------------------------------------------------------------------
        // Function: mainJump
        //----------------------------------------------------------------------------------------------------
        function mainJump():void
        {
            //trace("hello3");
            //===============================
            //if main isn't already jumping
            //===============================
            //trace("in mainJump()");
            if (!mainJumping)
            {
                //trace("hello4");
                mainJumping = true;
                jumpSpeed = jumpSpeedLimit*-1;
                mcMain.y += jumpSpeed;
            }
            else
            {
                //============================================
                //continue jumping if already in the air
                //============================================
                if (jumpSpeed < 0)
                {
                    //trace("hello2");
                    //jumpSpeed *= 1 - jumpSpeedLimit/125;
                    jumpSpeed *= 1 - jumpSpeedLimit/200;
                    if (jumpSpeed > -jumpSpeedLimit/5)
                    {
                        jumpSpeed *= -1;
                    }
                }
                trace("jumpSpeed: " + jumpSpeed);
                trace("jumpSpeedLimit: " + jumpSpeedLimit);

                if (jumpSpeed > 0 && jumpSpeed <= jumpSpeedLimit)
                {
                    //trace("hello");
                    jumpSpeed *= 1 + jumpSpeedLimit/50;
                    //trace("the jumpSpeed is: " + jumpSpeed);
                }
                //trace("hello5");

                mcMain.y += jumpSpeed;



                //============================================================
                // check collisions for fixed objects
                //============================================================
                for (var i:int = 0; i<fixedObjects.length; i++)
                {

                    var hitBlock = fixedObjects*;


                    if (mcMain.hitTestObject(hitBlock.mc) && mcMain.y < hitBlock.topside)
                    {
                        trace("hitBlock.topside collision");
                        mainOnGround = false;

                        mainJumping = false;

                        mcMain.y = hitBlock.topside - mcMain.height/2;
                        //break;
                    }
                    if (mcMain.hitTestObject(hitBlock.mc) && mcMain.y > hitBlock.bottomside)
                    {
                        trace("hitBlock.bottomside collision");
                        mainOnGround = false;

                        mainJumping = false;

                        mcMain.y = hitBlock.bottomside + mcMain.height/2;


                    }
                }
                //============================================================
                // check collisions for rotating_platforms
                //============================================================
                for (var i:int = 0; i<rotating_platforms.length; i++)
                {

                    var hitBlock = rotating_platforms*.mc.rotate0;


                    //trace(hitBlock.mc.x + "  " + hitBlock.mc.y)
                    if (mcMain.hitTestObject(hitBlock) && mcMain.y < hitBlock.topside)
                    {
                        trace("TOP");
                        mainOnGround = false;

                        mainJumping = false;

                        mcMain.y = hitBlock.topside - mcMain.height/2;

                    }
                    if (mcMain.hitTestObject(hitBlock) && mcMain.y > hitBlock.bottomside)
                    {
                        trace("BOTTOM");
                        mainOnGround = false;

                        mainJumping = false;

                        mcMain.y = hitBlock.bottomside + mcMain.height/2;// + 1;

                    }
                }
            }
        }
    }
}