PDA

View Full Version : (not another)Preloader Question



neworder
April 18th, 2004, 01:43 AM
Anybody have any code for a "Variable" preloader?

For example, I have a 1.5meg flash file that I have made that is 3mins long. Playback works fine without a loader if you can download at least 15k a sec. It seems like you could make a preloader that checks to see the speed of the download (say you sample a few seconds to get an average) and if you can download it faster than it can play it back, it would start before it finishes downloading. If you were on a modem only getting 4k a sec, it would know this and wait until the entire movie (or almost the entire movie) is downloaded before it starts playing. It makes no sense in having people wait if they don't have to.

I am still learning Action Script and have seen a lot of preloaders but they all seem to wait until the movie is all the way loaded before it allows it to play.

I have seen people use a preloader and just wait until half of the movie is loaded and then start playing it but it would be better to make a "smart" preloader.

Has anybody done tried this or am I missing something?

Adam
April 18th, 2004, 02:06 AM
The idea of the preloader is to check total bytes compared to bytes loaded....most people make sure the file is fully loaded ie:



total = this.getBytesTotal();
bytesLoadedSoFar = this.getBytesLoaded();
if(total==bytesLoadedSoFar){
play()
}


that's saying if the total loaded equals the total in the file, then play...you can set it up however you want:



total = this.getBytesTotal();
bytesLoadedSoFar = this.getBytesLoaded();
if(total==(bytesLoadedSoFar/2)){//see explanation below
play()
}


if(total==(bytesLoadedSoFar/2)) checks to see if the total bytes that are loaded equals half of the full amount of bytes for the file (bytesLoadedSo far/2 = bytesLoadedSo far divided by 2)...so it will start playing once the file is half loaded..

Adam