GrantPeck83
GrantPeck83

Reputation: 5

php xml into as3

I can't find out how to get some data from a PHP file across into Flash AS3. I can get a simple string across, however my data is XML data pulled from a database. I need the xml to be brought into AS3 and then I can forceDownload from within flash.

This is my php line which grabs the two columns of data.

list($data, $name) = mysql_fetch_array($queryDownload);

The $data is the XML code and $name is the name of the file.

How do I send that to AS3 in a way that keeps the data as XML data? and get AS3 to use that to create a downloadable file?

Upvotes: 0

Views: 953

Answers (2)

loxxy
loxxy

Reputation: 13151

Check the AS3 documentation for XML.

var xml:XML;

var urlRequest:URLRequest = new URLRequest("http://yourdomain.com/file.php");
var urlLoader:URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
urlLoader.addEventListener(Event.COMPLETE, urlLoader_complete);
urlLoader.load(urlRequest);

function urlLoader_complete(evt:Event):void { 

    xml = new XML(evt.target.data);    
}

In the above snippet the PHP file is named file.php & is located at yourdomain.com

Your PHP code simply needs : echo $data

Upvotes: 1

skovalyov
skovalyov

Reputation: 2099

You should send the XML object serialized as string and then create an XML object on the client using new XML(xmlString), where xmlString is the server response.

Upvotes: 0

Related Questions