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

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
Trackbacks
Comments are closed. You can contact me by email.