0

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?

  • The meaning of *well-formed* is specifically standardized in XML, I suggest to take a look into the Wikipedia entry if you want to understand what the message means: http://en.wikipedia.org/wiki/Well-formed_document – hakre May 24 '13 at 15:59
  • Also please check with everything done in related questions with the same error message and let us know what you did so far because of which question and what the outcome was - per each. This is important to make your question visible in context to the others of the website (also you might learn about what's going wrong more quickly): E.g. have you tried: [XML, TypeError: Error #1088: The markup in](http://stackoverflow.com/q/3514942/367456) ? – hakre May 24 '13 at 16:08
  • at first try to make your xml as simple as possible , one line like this: `echo "";` and see if it start to work – Ivan Chernykh May 24 '13 at 17:58

3 Answers3

0

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>";
?>
emilie zawadzki
  • 2,035
  • 1
  • 18
  • 25
0

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

Anil Gupta
  • 632
  • 4
  • 16
0

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.

Ali Albahrani
  • 105
  • 1
  • 1
  • 7