0

所以我有一个 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();
}
4

2 回答 2

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");
    }


}
于 2013-08-15T17:57:36.270 回答
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();
}
于 2013-08-15T17:22:28.043 回答