Search code examples
apache-flexactionscript-3

AS3: Socket timeout


I get a vague "Socket timeout." error on occasion when I am loading my site. I make various HTTP requests for PHP data and also am using a Loader() class instance. Can anyone shed some light on where this error might be coming from?

I wish there was more of an indication of where the error stemmed from...

Here is my code that I am using. There are multiple problems going on, but the most important is that catch{} catches an error on first load. I have a fade in function that only works if the loader is fully loaded and I know that all of my URL links work, so it can't be that.

  public function loadImage(url:String):void 
  {
   this._imageURL = url;
   this.alpha = 1.0; //need this because we might have just faded the image out

   _ldr.alpha = 0.0;
   _prog.alpha = 1.0;
   _sqr.alpha = 0.0;

   try 
   {
    _ldr.close();
    _ldr.unload();
   }
   catch(e:Error)
   {
    trace("error in bmdisplay: " + e.message);
   }

   if(!_imageURL)
   {
    return;
   }

   _loaded = false;
   _ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
   _ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
   _ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);
   _ldr.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
   _ldr.load(new URLRequest(_imageURL));
  }

Solution

  • Could you provide more precise information on what you're actually loading and how?

    You should be able to get the exact request throwing the error by listening for the securityError and ioError events on the contentLoaderInfo of the Loader object.

    Something like this:

    var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorListener);
    loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, errorListener);
    var request:URLRequest = new URLRequest(url);
    loader.load(request);
    
    ...
    
    private function errorListener(event:Event):void {
      var url_causing_the_error:String = LoaderInfo(event.target).loaderURL;
      ...
    }