I have a function in my AS3 that frequently calls a PHP file. Most of the time it works but occasionally it fails and throws the error I used in the title. I researched this fairly extensively and started capturing the event in the following manner:
public static function Bar():void {
var request:URLRequest = new URLRequest("path/to/file.php");
var requestVariables:URLVariables = new URLVariables();
var loader:URLLoader = new URLLoader();
requestVariables.event = "foo";
request.method = URLRequestMethod.POST;
request.data = requestVariables;
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.load(request);
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
loader.addEventListener(Event.COMPLETE, onIOComplete, false, 0, true);
}
private static function onIOComplete(e:Event):void
{
var loader:Loader = e.target as Loader;
if ( loader != null )
{
loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
loader.removeEventListener(Event.COMPLETE, onIOComplete);
}
Logger.log("LOADER COMPLETE");
}
private static function onIOError(e:IOErrorEvent):void
{
var loader:Loader = e.target as Loader;
if ( loader != null )
{
loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
loader.removeEventListener(Event.COMPLETE, onIOComplete);
}
Logger.log("ERROR: " + e.toString());
}
In spite of the above code, I am still seeing the stream error occasionally. Is there more I should/could be doing?
Apparently the issue was that the php file I was calling was making a network call using file_get_contents in a case where I should have been using cURL. Once I changed them the second network call stopped failing thus I stopped seeing the error.