所以我有一个ping服务器的代码,但它跟踪信息。我想改变它,并使用动态文本在舞台上显示ping信息。我该怎么办?这是我的代码:
var ldr:URLLoader = new URLLoader();
ldr.addEventListener(HTTPStatusEvent.HTTP_STATUS, ldrStatus);
var url:String = "URL-TO-SITE";
var limit:int = 10;
var time_start:Number;
var time_stop:Number;
var times:int;
ping();
function ping():void
{
trace("pinging", url);
times = 0;
doThePing();
}
function doThePing():void
{
time_start = getTimer();
ldr.load(new URLRequest(url));
}
function ldrStatus(evt:*):void
{
if(evt.status == 200)
{
time_stop = getTimer();
trace("got response in", time_stop - time_start, "ms");
}
times++;
if(times < limit) doThePing();
}
答案 0 :(得分:0)
我不确定这是否是您要求的,但如果您想要显示正在跟踪的信息,您必须在舞台上有一个文本字段,或者动态创建一个。你可以这样做,你想做一个文本字段:
import flash.text.TextField;
function ldrStatus(evt:*):void{
if(evt.status == 200)
{
time_stop = getTimer();
trace("got response in", time_stop - time_start, "ms");
var tf:TextField = new TextField();
addChild(tf);
tf.text = "got response in"+ (time_stop - time_start) + "ms";
}
times++;
if(times < limit) doThePing();
}
答案 1 :(得分:0)
它工作正常,我只是在舞台上创建了一个名为textBox的文本框,并在最后添加了一些代码。
var ldr:URLLoader = new URLLoader();
ldr.addEventListener(HTTPStatusEvent.HTTP_STATUS, ldrStatus);
var url:String = "http://google.com.net";
var limit:int = 10;
var time_start:Number;
var time_stop:Number;
var times:int;
ping();
function ping():void
{
trace("pinging", url);
times = 1;
doThePing();
}
function doThePing():void
{
time_start = getTimer();
ldr.load(new URLRequest(url));
}
function ldrStatus(evt:*):void
{
if(evt.status == 200)
{
time_stop = getTimer();
textBox.text = String("got response in", time_stop - time_start, "ms");
}
}