Log in

View Full Version : Preloader from numbers to %



nate51
12-03-2009, 04:04 PM
I have a preloader that works with a timeline animation and the original numbers were to count the load up for the file size. I tried to convert it to a percentage meter and for some reason the numbers just display as numbers.

The code is below and I am drawing blanks now, can anyone see where things are getting messed up?

code on the mc

onClipEvent (load) {
if (_parent.getBytesTotal() == _root.getBytesLoaded()) {
quickPlay = true;
} else {
preLoad = (_root.getBytesTotal() * 0.95); //percent to preload
}
_root.stop();
}

onClipEvent (enterFrame) {
gotoAndStop(loadedIndicatorFrame());
if (quickPlay == true) { //quickly play the anim
if (_currentframe == _totalframes) {
_root.gotoAndPlay("project");

}
} else { //wait for the preload
if (_root.getBytesLoaded() >= preLoad) {
_root.gotoAndPlay("project");
}
}
}

code on the first frame in the mc for the timeline animation

lastFrame = 1;

function loadedIndicatorFrame() {
var newFrame = int((_root.getBytesLoaded() / _root.getBytesTotal()) * 65) + 2;
if (newFrame - lastFrame > 4) { //too far
lastFrame += 4;
loadedText = int(_root.getBytesTotal() / 1024 * (lastFrame - 2) / 65) + "kb of " + int(_root.getBytesTotal() / 1024) + "kb";
} else if (newFrame - lastFrame > 0) { //normal move
lastFrame++;
loadedText = int(_root.getBytesLoaded() / 1024) + "kb of " + int(_root.getBytesTotal() / 1024) + "kb";
} else { //update the text only
loadedText = int(_root.getBytesLoaded() / 1024) + "kb of " + int(_root.getBytesTotal() / 1024) + "kb";
}
return lastFrame;
}

I tried to change over the "kb" to "%" and that worked alright but the numbers did not go from 0 to 100.

Any help or direction on what is going wrong would be great.