0 Replies Latest reply on Dec 24, 2009 12:37 PM by socialvisionklk

    How to make URLLoader return an AsyncToken?


      Hi all,


      I was trying to retrieve binary data over HTTP for my Flex application, and was running into some stumbling blocks. HTTPService did not seem to deal with binary data well, people said to use URLLoader. But URLLoader does not have the nice AsyncToken/IResponder interface that HTTPService provides.


      So, I did some searching and could not find anyone extending URLLoader to provide this kind of functionality. I went ahead and took a stab at it myself: http://pastebin.com/d7369d0e0


      Basically it wraps a URLLoader and an AsyncToken, and maps the COMPLETE, IO_ERROR, and SECURITY_ERROR events from URLLoader to results/faults that get raised on the AsyncToken.


      Basic usage:

      var tidbitLoader:AsyncURLLoader = new AsyncURLLoader();
      .dataFormat = URLLoaderDataFormat.BINARY;

      var asyncToken:AsyncToken = tidbitLoader.load(new URLRequest("http://localhost/SampleTidbit.swf"));


      public function result(resultEvent:Object):void

      public function fault(faultEvent:Object):void
      var fault:FaultEvent = faultEvent as FaultEvent;
      ("fault: " + fault.toString());


      Is this the right way to approach the problem? Are there existing solutions? I would love to hear feedback.