0

I have a URLRequest loading on a mobible device. If the internet is spotty it stops. Most of the time it works but sometimes it gets stuck on a certain percentage. Is there a way to see if the loading has stopped and have it "retry" after 3 seconds or something of that sort? Can it also try like, lets say, 10 times and after that throw an error message so I can tell users?

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)+ "%";
    }
Papa De Beau
  • 3,744
  • 18
  • 79
  • 137
  • Out of curiosity, have you tried adding a listener for `IOErrorEvent.IO_ERROR` to the `contentLoaderInfo` object to make sure you aren't erroring out in the middle (rather than "getting stuck")? – Josh May 23 '14 at 23:01
  • I recently added it. However is not that for the first initial call to see if the ull is valid etc? – Papa De Beau May 23 '14 at 23:02

1 Answers1

2

Unfortunately, Flash does not have a built-in system for such kind of tasks.. But it's not that hard to implement. You can use the idleTimeout property of the URLRequest, to set specific timeout: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html#idleTimeout Then you can catch the error event which will be fired because of a timeout, and make a retry.

I usually don't use that and I have a simple Timer object with let's say 10 seconds interval. When I start loading (loader.load()) I also start the timer (timer.start()). There are two simple properties - isLoading <Boolean> and retries <uint>. So then TIMER_TICK event fires, I check if (isLoading), and if so - stop the request (close, unload, everything you can do within the loader, but with try-catch statement), and then start the request again. Of course - increase the retries variable, and if it's equal to your max retries var - it stops loading.

Good luck!

Andrey Popov
  • 7,362
  • 4
  • 38
  • 58