问题
I am trying to get some basic data passed from PHP to Flash. From reading on the topic I understand the best way is to create XML with PHP then read it in Flash. I am trying to start out simple so here is my PHP code:
<?php
header('Content-Type: text/xml');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
echo "<userData>";
echo "<firstName>John</firstName>";
echo "<lastName>Smith</lastName>";
echo "</userData>";
?>
And here is my Flash code:
var xml:XML = new XML();
var url:URLRequest = new URLRequest("data.php");
var loader:URLLoader = new URLLoader(url);
loader.addEventListener("complete", xmlLoaded);
function xmlLoaded(event:Event):void
{
xml = XML(loader.data);
trace("Data loaded.");
trace (loader.data);
};
I've seen some tutorials that use this approach and it works however in Flash I receive this error:
TypeError: Error #1088: The markup in the document following the root element must be well-formed.
Can anyone determine why I get this error or provide another way of doing this?
回答1:
Try to add markup < data >:
<?php
header('Content-Type: text/xml');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
echo "<data>";
echo "<userData>";
echo "<firstName>John</firstName>";
echo "<lastName>Smith</lastName>";
echo "</userData>";
echo "</data>";
?>
回答2:
I am not expert in flash but think following link may help you http://www.lashf.com/page/Flash_and_PHP http://forums.adobe.com/message/4301986
回答3:
It is very clear that your XML format is not accepted by FLASH. FLASH read a very formatted XML so you need to be very accurate in the way you write it.
I suggest using a XML class form php to build your XML like DOMDocument. I am using that class in my project for FLASH and its works fine.
Good luck.
来源:https://stackoverflow.com/questions/16738581/passing-data-from-php-to-flash