Groups | Blog | Home
all groups > flash actionscript > june 2004 >

flash actionscript : Intelligent Preloader?


nineveh
6/20/2004 11:06:33 PM
I'm trying to create an intelligent preloader that will calculate the user's
connection speed and then preload just enough of the file (according to the
detected connection speed) and start streaming the SWF as the rest of the file
is loading. This would be similar to streaming an online Windows Media or Real
Media file whereas the target file buffers and then begins to stream as the
rest of the file is downloaded. However, I want to take it a step further and
caclulate the connection speed and preload (buffer) a portion of the SWF file
according to the connection speed. In other words, a user that begins to
preload the file at a slower speed will have to buffer more of the SWF file
before it begins to play; furthermore it begins to play as the rest of the file
is downloading.

Is there such a way to accomplish this? Is it a worthwhile pursuit?

Here is my current preloader script:



MovieSize = _root.getBytesTotal();
LoadedSize = _root.getBytesLoaded();
PercentLoaded = LoadedSize/MovieSize;
BoxWidth=PercentLoaded*100;
_root.GrowBar._xscale=BoxWidth;
if (PercentLoaded<30) {
gotoAndPlay("Preload");
} else {
gotoAndPlay("Start");
}
kglad
6/21/2004 5:36:58 AM
estimating download speed is straight-forward:

startTime=getTimer()/1000;
preloadI=setInterval(preloadF,100);
function preloadF(){
dlRate=_root.getBytesLoaded()/(getTimer()/1000-startTime);
}

however, there's not way for flash to calculate the time required to play your
movie, even assuming that it has an end. if your movie has an end and you can
time the length of time for your movie to play from beginning to end, you can
design a "smart" preloader. for example, if playTime=time in seconds for your
movie to play from beginning to end you can use:

startTime=getTimer()/1000;
preloadI=setInterval(preloadF,100);
function preloadF(){
dlRate=_root.getBytesLoaded()/(getTimer()/1000-startTime);
if(_root.getBytesLoaded()>=_root.getBytesTotal()-playTime*dlRate){
//start playing your movie. the vagaries of the internet not withstanding,
you should complete dl of your movie before playTime
}
}
}
nineveh
6/21/2004 6:11:18 AM
Thanks. What do you think about this adaptive preloader:

http://www.wildform.com/tutorials/adaptive_preloader/#5

AddThis Social Bookmark Button