1

I have a Flash program that needs to make url requests to send data to the server at various times. I want Flash to keep trying the request until it is successful. How do I make sure Flash keeps trying the request and doesn't time out and quit trying to send? My code looks like this:

urlRequest = new URLRequest("https://xyz.php");
var variables:URLVariables = new URLVariables();
urlRequest.method = URLRequestMethod.POST;
variables.session_id = sessionId;
... 

urlRequest.data = variables;
urlLoader = new URLLoader(urlRequest);
urlLoader.dataFormat  = URLLoaderDataFormat.VARIABLES;
Boundless
  • 2,444
  • 2
  • 25
  • 40

1 Answers1

1

You can add a listener to IOErrorEvent.IO_ERROR and try again if it fails. There are other errors possible, like security errors that you could also listen for, though the chance of those failing once and then magically succeeding in the future is far less likely.

James Tomasino
  • 3,520
  • 1
  • 20
  • 38
  • I can easily add a listener. How would I send the data again, if I detect the error? – Boundless Mar 26 '12 at 15:34
  • Just use the urlLoader.load() method again. I'd recommend making the urlLoader a class member so you can refer to it willy-nilly around your class. That's about it. – James Tomasino Mar 26 '12 at 18:10
  • Thanks, this helped me create a solution. I ended up making a separate class to send the data, so I could access it willy-nilly when I need to resend it due to an error. – Boundless Mar 26 '12 at 21:04