I started to work on a new code (last one was for a fighting game but as the guy never finished them, I can't do anything else atm) that does work---but it freezes the game, why? Here's the code.

stop();
xSpeed = 0;
maxSpeed = 20;
maxSpeed2 = -20;
slowSpeed = 1;
var grav:Number = 0;
var gravity:Number = 10;
var maxJump:Number = -9;
var toughingGround:Boolean = false;
Son.onEnterFrame = function() {
this._x += xSpeed;
//gravity
Son._y += grav;
grav += gravity;
while (ground.hitTest(Son._x, Son._y, true)) {
}
if (ground.hitTest(Son._x, Son._y+5, true)) {
toughingGround = true;
jumping = false;
} else {
toughingGround = false;
}
if (Key.isDown(Key.SPACE) && toughingGround) {
jumping = true;
grav-maxJump;
} else if (Key.isDown(Key.RIGHT)) {
this._xscale = 100;
if (xSpeed>10) {
this.gotoAndStop("SonRun");
} else {
this.gotoAndStop("SonWalk");
}
if (xSpeed<maxSpeed) {
xSpeed += 1;
}
} else if (Key.isDown(Key.LEFT)) {
this._xscale = -100;
if (xSpeed<-10) {
this.gotoAndStop("SonRun");
} else {
this.gotoAndStop("SonWalk");
}
if (xSpeed>maxSpeed2) {
xSpeed -= 1;
}
} else if (xSpeed>0) {
this.gotoAndStop("SonBreak");
xSpeed -= slowSpeed;
} else if (xSpeed<0) {
this.gotoAndStop("SonBreak");
xSpeed += slowSpeed;
}
};
So what's freezing the game? The line

while (ground.hitTest(Son._x, Son._y, true)) {
is causing it to freeze up. I tested it and when I change the word "while" to "if" Sonic falls off screen, but the game no longer freezes. I spent over an hour with an friend to try and fix this and I even messaged the guy who made the tut videos (still awaiting a reply), but so far no luck is fixing this.

Can anyone tell me how to fix this? I really hate AS, I do, but it is what it is. I can't fix it so asking for help. If get a reply back from the guy I'll post here saying so.

https://www.youtube.com/watch?v=mkrt24B_Lvs&index=59

AND BEFORE YOU ASK! No, his fla files are a unexpected format so flash 8 can't open them.