Script running slowly - uploader (going nuts)

EDIT: Solved, problem was that the formatDecimalfunction a Number returnvalue expected but it returned a String that had to be casted. That and applying strict datatyping to the function did the trick.

I already lost 8hours of my day yesterday trying to figure out the source of the problem and a sollution so far.

What I have is an uploader which can handle big files (<100MB) … in theory.
The uploading itself works, my progressbar works, but three’s a problem displaying the text about the progress. I use the filereference class and an listener.onProgress to display the progress of the upload.

The problem is that after a while when I upload a big file (45MB) I get a warning that the script is running slowly and that this might cause flash or the computer to slow down. When I answer no to the question if I want to abort the script, it just continues, but it’s possible that it shows the same error after a while.

This is the script that causes the problem, it is executed at each onProgress event:

function updateProgress(bytesLoaded:Number, bytesTotal:Number):Void{
var progresstotaal:Number = 190; 
var percentage:Number = Math.round(bytesLoaded / bytesTotal * 100);
var verzonden:String = getFileSize(bytesLoaded);
var totaal:String = getFileSize(bytesTotal);
uploaderMovie.mc_uploading.txt_status.text = percentage + "% " + uploaderMovie.VerzondenTekst + verzonden + uploaderMovie.VanTekst + totaal;
uploaderMovie.mc_uploading.mc_progress._width = Math.round(bytesLoaded / bytesTotal * progresstotaal);
if((bytesTotal - bytesLoaded) < 1024){
delete uploaderMovie.mc_uploading.btn_cancel.onRelease;
}
}; /* updateProgress */
 
function getFileSize(bytes:Number):String{
var filesize:String;
if((bytes/1024)/1024 > 1){
filesize = formatDecimals((bytes/1024)/1024, 2) + "MB";
} else {
filesize = Math.round(bytes/1024) + "kB";
}
return filesize;
}; /* getFileSize */
 
function formatDecimals(num:Number, digits:Number):Number {
if (digits <= 0) {
return Math.round(num); 
} 
var tenToPower = Math.pow(10, digits);
var cropped = String(Math.round(num * tenToPower) / tenToPower);
if(cropped.indexOf(".") == -1) {
cropped += ".0";
}
var halves = cropped.split(".");
var zerosNeeded = digits - halves[1].length;
for (var i=1; i <= zerosNeeded; i++) {
cropped += "0";
}
return(cropped);
}; /* formatDecimals */

(the formatDecimals-method I got off the internet)

I’m not exactly sure what’s so heavy about this code that causes the warning. When I comment out the call to the getFileSize-function and the filling of the text-field, it works well and I don’t get the error.

I REALLY need this problem fixed!