0

我在移动设备上加载了 URLRequest。如果互联网参差不齐,它就会停止。大多数时候它可以工作,但有时它会卡在一定的百分比上。有没有办法查看加载是否已停止并在 3 秒后“重试”或类似的东西?它也可以尝试 10 次,然后抛出错误消息以便我可以告诉用户吗?

public function loadIt()
{
var theImage = "http://www.Example.com/Example.png"; // real url not given here
my_loader.load(new URLRequest(theImage));
my_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, startListener);

my_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressListener);
    if(autoPlayAd=="true")
    {
    playAd();
    }
}



public function progressListener(e:ProgressEvent):void
    {
    loadingStatus.Per.text = Math.floor((e.bytesLoaded/e.bytesTotal)*100)+ "%";
    }
4

1 回答 1

2

不幸的是,Flash 没有用于此类任务的内置系统。但实现起来并不难。您可以使用 URLRequest 的 idleTimeout 属性来设置特定的超时时间:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html#idleTimeout然后 您可以捕获错误由于超时而触发的事件,然后重试。

我通常不使用它,我有一个简单的 Timer 对象,假设间隔为 10 秒。当我开始加载 ( loader.load()) 时,我也会启动计时器 ( timer.start())。有两个简单的属性 -isLoading <Boolean>retries <uint>。然后 TIMER_TICK 事件触发,我检查if (isLoading),如果是 - 停止请求(关闭,卸载,您可以在加载程序中执行的所有操作,但使用 try-catch 语句),然后再次启动请求。当然 - 增加retries变量,如果它等于你的 max retries var - 它会停止加载。

祝你好运!

于 2014-05-23T06:32:16.480 回答