FlashXMLHttpRequest: cross-domain requests

I've been working with Jason Levitt (from Yahoo) recently to iron the wrinkles out of my Flash-based technique for making cross-domain requests. The main focus was to extend the reach of the technique to a larger audience, by adding support for Flash 7, which is more widely deployed than Flash 8.

Try the new FlashXMLHttpRequest demo.


Brad Neuberg's awesome work on DojoExternalInterface gave us a major boost. It emulates the most recent javascript to flash communication API (ExternalInterface, in Flash 8) accross platforms including Flash 7. The library hides differences with browsers and flash versions as much as possible, and works around various performance limitations.

Thanks again to Jason for his interest, feedback and support. I'm pretty excited to see what cool stuff he'll cook using this and the new web APIs from Yahoo.


If you only want to deploy this component, you can download the "binary" package.
To modify the flash source files and re-build them, get the "source" package.


As you can see in the demo/index.html file, after including dojo.js and FlashXMLHttpRequest.js, you'll need to initialize dojo and the flash object by calling InitFlash with the name of a function. That function will be invoked once the flash object is loaded and ready to make requests.
From there on, you can create FlashXMLHttpRequest instances and use the "open", "onload" and "send" methods almost as you would with a regular XMLHttpRequest object. You can also call "setRequestHeader", but only to set the content type request header.

More generally, FlashXMLHttpRequest still has some limitations, due to the native Flash capabilities.
First, access to other domains is restricted by use of a crossdomain.xml file.
Second, you can only make GET and POST requests. It will become possible to support other verbs, such as PUT, DELETE or HEAD, with the new APIs provided by Flash 8.5.


Let me know if FlashXMLHttpRequest is useful to you and if you encounter any bugs. Here's a more convenient permalink to this post: http://blog.monstuff.com/FlashXMLHttpRequest.

Update (2007/01/29): It seems that Yahoo has removed their crossdomain.xml file from http://api.search.yahoo.com/crossdomain.xml
I'm not sure when this happened. The new domain is http://search.yahooapis.com/crossdomain.xml.

Posted by Julien on June 04, 2006. Permalink
Comments
comments powered by Disqus

Julien, awesome work! You should submit this to the Dojo project. I'm glad that dojo.flash was useful for you, and I look forward to playing with your code some more.

Best,
Brad

Posted by: Brad Neuberg at June 5, 2006 02:49 PM

Julien,

Have you tried if FlashXMLHttpRequest is capable of accessing the partial text as the request is still loading, or when the response is a HTTP keep-alive type? If it is, it might be useful for a chat script.

Roy

Posted by: Roy at July 11, 2006 12:57 AM

Hi Roy,

No I wasn't able to make the response available as it arrives. Again this is something that Flash 8.5 might improve on, I'd need to look some more, either thru the improved HTTP APIs or thru the socket APIs.

Posted by: Julien Couvreur at July 11, 2006 03:40 PM

It's not working with UTF-8 characters (unicode), that's a bug probaly.

Posted by: Ramon at August 5, 2006 10:52 AM

Actually I've been rethiking about it and I think the problem isn't with the utf-8 chars but with the comments within files xml style. ()

best,

Posted by: Ramon at August 5, 2006 01:06 PM

Kyle dropped me a note about his project, which is similar to FlashXMLHttpRequest. That may be interesting to some readers since I don't maintain this project anymore.

"I've read about and seen your flash-based cross-domain ajax solution from a few years back. I was wondering if you had checked out flXHR (http://flxhr.flensed.com)? It does something very similar, but it does so by implementing an identical API to the native XHR object, which makes it easy to drop flXHR into existing code without any changes. I even have plugins for jQuery and Dojo which make it even easier and more flexible to work with. " -- Kyle

Posted by: Julien at April 26, 2009 10:23 PM

Boris Reitman has been working on a similar project. In his own words:
"I was inspired by your article and wrote this:
http://code.google.com/p/crossxhr/
I'm also providing flash source for the object. I can't remember now why your solution didn't work for me and I had to write my own."

Posted by: Julien at May 3, 2009 10:21 AM

Escort Services If we wish to free ourselves from enslavement, we must choose freedom and the responsibility this entails. coolserg9981

Posted by: Mcbott at August 5, 2009 04:53 AM

Sensual massage I choose not to think of my life as surviving, but coping. coolserg9981

Posted by: Laface at August 5, 2009 07:00 AM
Trackbacks