客户端网速的测量——ActionScript实现.backup

package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.*;
import flash.events.ErrorEvent;
import flash.events.IOErrorEvent;
import flash.net.URLRequest;
import flash.text.*;
import flash.utils.*;
import flash.display.GradientType;

public class LoadImage extends Sprite
{
private var loader:Loader=new Loader();
private var loadDisplay:TextField= new TextField();
private var st=(new Date()).getTime();
private var et;
private var delay:Number=50*1000;
private var currentfileziize;//记录已经下载了多少字节,对于大文件很有用
private var myTimer=setTimeout(stopTimeHandler,delay);
private var stgb=new Sprite;
private var stg=new Sprite();

public function LoadImage()
{
//var url=new URLRequest("http://i0.sinaimg.cn/ent/y/w/2008-11-24/U1513P28T52D3414F872DT20081124143718.jpg?id=979976");

var url=new URLRequest("http://g3.letv.cn/vod/v1/MTUvNy8yNy8yMTUxMzE1OTg1LjAuZmx2");
loader.load(url);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderComplete);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,loaderProgress);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,loaderError);
addChild(loader);
   addChild(loadDisplay);
  //stage.x=100;
//stage.y=100;
//loadDisplay.autoSize=TextFieldAutoSize.CENTER
//loadDisplay.x=0;
//loadDisplay.y=0;
//loadDisplay.width=300;


}
public function loaderProgress(evt:ProgressEvent):void
{
var percent:Number=Math.round((evt.bytesLoaded/evt.bytesTotal)*100);
currentfileziize=evt.bytesLoaded;
loadDisplay.text+=percent+"%";

}
public function loaderComplete(evt:Event):void
{
loadDisplay.text="complete\r";
inerdisply();
}

public function loaderError(evt:IOErrorEvent):void
{
loadDisplay.text="error\r";
inerdisply();
}
public function stopTimeHandler():void
{
loader.close();
loadDisplay.text="stopTime\r";
inerdisply();
}
private function inerdisply():void
{
et=(new Date()).getTime();
loadDisplay.text+="您已经下载的文件大小为: "+String(currentfileziize/1000)+" KB\r";
loadDisplay.text+="您访问时间为: "+String((et-st)/1000)+" s\r";
loadDisplay.text+="您的网速为: "+String(Math.round(8*loader.contentLoaderInfo.bytesLoaded/(et-st)))+" Kbps\r";
}
}
}

你可能感兴趣的:(Date,function,String,import,actionscript,delay)