If you are making a HTTPService call in Flex, you need to make sure that the domain specified in the url attribute is the domain from where your application was downloaded or there is a crossdomain.xml file granting access to your application’s originating is available on the domain specified in the HTTPService url attribute.

Take a look at the following example. Trying to load a XML file :-

<s:HTTPService resultFormat="e4x"
 url="http://news.bbc.co.uk/nol/shared/bsp/hi/services/desktop_alerts/xml/ukfs/alert_data.xml" />

If you run the above code, you get the following error :-

[RPC Fault faultString="Security error accessing url" faultCode="Channel.Security.Error" faultDetail="Destination: DefaultHTTP"]
 at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:345]
 at mx.rpc::Responder/fault()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\Responder.as:68]
 at mx.rpc::AsyncRequest/fault()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:113]
 at DirectHTTPMessageResponder/securityErrorHandler()[E:\dev\4.x\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:432]
 at flash.events::EventDispatcher/dispatchEventFunction()
 at flash.events::EventDispatcher/dispatchEvent()
 at flash.net::URLLoader/redirectEvent()

This means the URL we are trying to access does not have a crossdomain.xml file. And as is obvious, we can not ask for one in every case.

As I started looking into YQL recently, I figured this could be done with YQL. Here is a complete example I came up with that uses YQL to query the same URL that we could not access above and it parses the XML and displays in a grid.

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
 xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955"
 minHeight="600" initialize="doInit()">

 <!-- Place non-visual elements (e.g., services, value objects) here -->
 <s:HTTPService resultFormat="e4x"
 url="{yql_url('http://news.bbc.co.uk/nol/shared/bsp/hi/services/desktop_alerts/xml/ukfs/alert_data.xml')}" />

 import mx.rpc.events.ResultEvent;

 [Bindable] private var items:XMLList ;

 private function doInit():void

 private function yql_url(url:String):String
 var str:String = 'http://query.yahooapis.com/v1/public/yql?q=';
 var query:String = 'select * from xml where url="';
 query = query + url + '"';
 return str + encodeURI(query);

 private function resultHandler(event:ResultEvent):void
 var data:XML = new XML(String(event.result));
 items = data.results.stories.story;


 <mx:DataGrid id="newsList" dataProvider="{items}" width="500" height="200">
 <mx:DataGridColumn dataField="headline" />


Basically, what is happening here is I am sending a query to the YQL which looks something like this.


That does the trick. Returns me an XML as I wanted and then its upto me to do whatever I want with the XML.

I am actually wondering why is YQL not as widely used or heard about as it should be.

Tagged with:  

3 Responses to Accessing a URL with Flex and YQL when there is no crossdomain.xml

  1. Alan says:

    I am new to YQL and now i can’t figure out how to get data from a url which does not contain xml extension. For example:

    Flat String:


    Or JSON object:


    The returned result is a bunch of data. Could you please guide me how to write a YQL query to get it?

    Thank you

  2. Anuj Gakhar says:

    Alan, sorry for the delay in reply. Can I have a look at your existing YQL? You can play around with YQL in the console http://developer.yahoo.com/yql/console/

  3. Waouh, neat stuff!!
    It also works for JSON calls (spent some time to figure the syntax out, though) :
    select * from html where url=”http://www.agon-online.com/restserver/world_highscore/web_get_user_position?application_id=361DEC9C384AEFFCD6255C3F7B12F1E288691268&leaderboard_id=0&user_name=user_agon”

    Thanks for sharing this.

    Best regards,

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 445 other subscribers

© 2011 Anuj Gakhar
%d bloggers like this: