Skip navigation
Currently Being Moderated

load XML file from addon domain without cross-domain Policy file

Aug 5, 2012 3:51 AM



Assuming that there are two addon domains on the same server: /public_html/       and      /public_html/




I try to load XML file from into without using cross-domain policy file (since it doesn’t work on xml files in my case).


So the idea is to use php file in order to load XML and read it back to flash.


I’ve found an interesting scripts that seems to do the job but unfortunately I can't get it to work. In my opinion there is somewhere problem with AS3 part. Please take a look.


Here are the AS3/PHP scripts:






AS3 (.swf in



// location of the xml that you would like to load, full http address

var xmlLoc:String = "";


// location of the php xml grabber file, in relation to the .swf

var phpLoc:String = "loadXML.php";



var xml:XML;

var loader:URLLoader = new URLLoader();

var request:URLRequest = new URLRequest(phpLoc+"?location="+escape(xmlLoc) );


loader.addEventListener(Event.COMPLETE, onXMLLoaded);

loader.addEventListener(IOErrorEvent.IO_ERROR, onIOErrorHandler);





function onIOErrorHandler(e:IOErrorEvent):void {

    trace("There was an error with the xml file "+e);


function onXMLLoaded(e:Event):void {

    trace("the rss feed has been loaded");

    xml = new XML(;

    // set to string, since it is passed back from php as an object

    xml = XML(xml.toString());


    xml_txt.text = xml;









PHP (loadXML.php in




header("Content-type: text/xml");

$location = "";

if(isset($_GET["location"])) {


    $location = $_GET["location"];

    $location = urldecode($location);



$xml_string = getData($location);


// pass the url encoded vars back to Flash

echo $xml_string;




//cURLs a URL and returns it

function getData($query) {


    // create curl resource

    $ch = curl_init();


    // cURL url

    curl_setopt($ch, CURLOPT_URL, $query);


    //Set some necessary params for using CURL

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);


   //Execute the curl function, and decode the returned JSON data

    $result = curl_exec($ch);

    return $result;


    // close curl resource to free up system resources




  • Currently Being Moderated
    Aug 5, 2012 4:37 AM   in reply to klinek3

    Do you get either of the two traces from your swf functions?  If you get the one from the onXMLLoaded function, have you traced the  If you get the one from the onIOErrorHandler function, is the swf file in the same folder as the html page that embeds it?

    Mark as:
  • Currently Being Moderated
    Aug 5, 2012 6:40 AM   in reply to klinek3

    What is the trace you get from the onIOErrorHandler?

    Mark as:
  • Currently Being Moderated
    Aug 5, 2012 1:20 PM   in reply to klinek3

    I just recreated your scenario using your code as shown and the textfield displayed the xml file contents as expected. 


    You might need to look into the permissions for your php file or the settings on your server (I am assuming you are testing on a server - if not, do so).


    Sometimes the easiest way to reconcile a problem is to limit the number of variables in it that are possible contributors.  In your case, you could have the php file echo simple text instead of trying to load the xml file and see if that displays.  If the php file doesn't echo the simple text, then the problem lies in something with your php file, though I would say it is not the code in the file unless your server uses an older version of php than your code.

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points