-1

I am using urlLoader to load some remote content and then listen for Event.COMPLETE and IOErrorEvent.IO_ERROR.

When I get IOErrorEvent.IO_ERROR I retry the original urlLoader request.

This all works fine, however I wish to extend to support multiple request which may overlap, some on error and some not. As such I need a way to tell the function called by IOErrorEvent.IO_ERROR which request has the error.

I am thinking that if I could include a request id number this would be a neat solution.

Can IOErrorEvent.IO_ERROR include extra data?

Its possibly I am completing missing something obvious here in terms of approaching this problem.

Mar
  • 313
  • 3
  • 15
  • 2
    OOP solution: make it a class. Make a class that re-tries loading the given URL until success. Basically, you need it to have 2 interfaces: method **.load(url:String):void** and complete event (or callback). Now make several instances of that class, 1 per each file you need to load. – Organis Jun 02 '17 at 13:11
  • 1
    Every `Event` has a `currentTarget` property which references the object you attached the listener to. So in your error handler you can gain a reference to the URL loader by doing `event.currentTarget` – BadFeelingAboutThis Jun 02 '17 at 15:54

1 Answers1

0

Append the desired data to the listener

urlLoader.addEventListener(IOErrorEvent.IO_ERROR, IOError(myData));

Then use return function as below

private function IOError(myData:String):Function {
    return function(event:IOErrorEvent):void {
        trace(myData);
    }
}
Mar
  • 313
  • 3
  • 15
  • 2
    This is how memory leaks are born. If you are going to do it this way (which most would advise you not to), you'd better pass the weak flag on your listener (fifth argument on addEventListener) otherwise you'll have no easy way to remove that listener to an anonymous function. Event Listeners with anonymous functions can easily lead to disaster – BadFeelingAboutThis Jun 02 '17 at 15:49