PDA

View Full Version : Real quick preloader question.


imagius
09-28-2006, 12:46 AM
bytes_loaded = Math.round(this.getBytesLoaded());
bytes_total = Math.round(this.getBytesTotal());
getPercent = bytes_loaded/bytes_total;
this.loadText = Math.round(getPercent*100)+"%";
if (bytes_loaded == bytes_total) {
this.gotoAndPlay(3);
}
that is in frame 1, there is a blank text field (dynamic) with the var name of loadText.

this.gotoAndPlay(1);
That is in frame 2.

The problem is that when I hit ctrl+enter and do the simulated load thing it goes to 1% or 2% and then stops updating the number, even though in the bandwith profiler and streaming graph you can clearly see it is still loading and is far beyond the 2% it claims.

I think the tutorial I stole the code from is not meant for flash 8, any ideas on how to fix it?

colfaxrev
09-28-2006, 01:06 AM
well... if you are using attachMovie() anywhere, this will break your preloader unless you do some special stuff to fix it. If that is the problem I will tell you what that is, but i don't want to explain it if i don't have to.

also, instead of giving the text field a var value. give it an instance name. something like kbText.

now update the text by using kbText.text = Math.round(getPercent*100)+"%";

also, i do something more like this for my preloaders...


stop();

/*

Preloader Code. Deletes itself when finished, using delete this.onEnterFrame;

*/

preload_bar_mc._width = .1;

this.onEnterFrame = function()
{
var percent = Math.floor((getBytesLoaded() / getBytesTotal()) * 100);
kbText.text = Math.floor(getBytesLoaded()/1000)+"kb / "+Math.floor(getBytesTotal()/1000)+"kb";
preload_bar_mc._width = percent * 2;
if (percent >= 100)
{
play();
delete this.onEnterFrame;
}
}

imagius
09-28-2006, 01:56 AM
Worked like a charm, thank you so much.

termination0001
09-28-2006, 02:23 AM
also, i can easily work for flash 8 because all flashes up to 8 use both actionscript classes 1 & 2