View Full Version : Bandwidth Detection
devcajun
11-25-2008, 03:37 PM
Hi,
I am trying to figure out how to display a swf file transfer rate. I can do this with a FLV no problem but am trying to figure out the same for a swf or other file pulled in using the Loader class
thanks
devcajun
11-25-2008, 03:44 PM
found this but was looking for an AS3.0 solution
onClipEvent(load){
/*
Calculate approximate kbps after test swf loads
*/
function getkbps(startTime,sizeInBytes) {
elapsedTimeMS = getTimer() - startTime; // time elapsed since start loading swf
elapsedTime = elapsedTimeMS/1000; //convert to seconds
sizeInBits = sizeInBytes * 8; // convert Bytes to bits,
sizeInKBits = sizeInBits/1024; // convert bits to kbits
kbps = (sizeInKBits/elapsedTime) * 0.93 ; // IP packet header overhead around 7%
return Math.floor(kbps); // return user friendly number
}
/*
Load test.swf with a unique time to work around browser caching.
Browser will always load a new copy of SWF because url is different each time.
*/
now = new Date(); // create date object
nocacheStr = "?" + now.getTime();
this.loadMovie("test.swf");
}
onClipEvent(enterFrame){
// do not execute code until SWF begins to load
if(this._url != _root._url){
if(typeof start == "undefined") {start = getTimer();} // set start time once
if(this.getBytesLoaded() < this.getBytesTotal()){ // not yet loaded
_root.statusmsg = "Checking Bandwidth";
//------ checking bandwidth message true------
}
// swf loaded call getkbps()
if(this.getBytesLoaded() == this.getBytesTotal()){
_global.bw = getkbps(start,this.getBytesTotal());
_root.statusmsg = "Bandwidth = " + getkbps(start,this.getBytesTotal()) + " kbps";
_root.gotoAndStop('bw_done');
}
}
}
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.