Why does this cause Player to time out?

I am using the following code to allow a user to control how long and how many times a tone plays. It also causes a ball to be highlighted when the tone is playing (normal_mc is a movie clip sitting on top of a highlighted version). The sound part of this works perfectly. But if the combination of tone lengths and times yields a total time of more than about 15 seconds, it causes Flash Player to display the message about a script causing Flash Player to run slowly. The code changing the normal_mc alpha doesn’t work properly with the wait function in place, either.

Apparently, my wait function looks like an infinite loop to Player for some reason. Can someone explain why that is and let me know if there is something I can do to prevent it. Also - why does the wait function prevent some of the code from executing properly, but not all of it. The sound does start and stop when it should, but the highlighting all seems to execute only after the last for loop has completed.

//function to set delay between times tones start playing
function wait(ms){
 waitTime = new Date();
 do{
  checkTime = new Date();
  timeElapsed = checkTime.getTime() - waitTime.getTime();
 } while(timeElapsed <= ms);
}
//plays tone sequence "n" times, for "m" milliseconds each
play_btn.onPress = function(){
 n = 5;
 m = 750;
 for(i = 1; i <= n; i++){
  ball_mc.normal_mc._alpha = 0;
  startingTime = new Date();
  tone_snd.start();
  wait(m);
  ball_mc.normal_mc._alpha = 100;
  tone_snd.stop();
 }
}

Thanks,

Jim