0

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?

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your reply, would it be then possible to use that XML to create a download such as: fileReference.download();
why not? parse through the nodes of the xml, get the file path & use fileReference.download(<file path>)
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.