Dynamically generated XML from PHP to ActionScript 3

I am trying to dynamically create an XML file using php, for example:

header ("content-type: text/xml"); // create doctype $dom = new DOMDocument("1.0"); // create root element $root = $dom->createElement("tracklist"); $dom->appendChild($root); $dom->formatOutput=true; // create child element foreach ($commonPlaylist as $value) { $trackArray = getTrackForID($value['ID']); $item = $dom->createElement("track"); $root->appendChild($item); foreach ( $trackArray as $key => $value) { $attr = $dom->createAttribute($key); $item->appendChild($attr); $attrValue = $dom->createTextNode($value); $attr->appendChild($attrValue); } } echo $dom->saveXML(); 

File output normal working xml

 <?xml version="1.0"?> <tracklist> <track ID="4" title="Track01" artist="Artist01" url="" length="" coverURL=""/> <track ID="1" title="Track02" artist="Artist02" url="" length="" coverURL=""/> <track ID="8" title="Track03" artist="Artist03" url="" length="" coverURL=""/> </tracklist> 

However, if I want to get this data in as3 with the following code:

 var myLoader:URLLoader = new URLLoader(); myLoader.load(new URLRequest("getPlaylist.php")); myLoader.addEventListener(Event.COMPLETE, processXML); function processXML(e:Event):void { var myXml:XML= new XML(e.target.data); trace(myXml); // The variable is being traced. 

}

I don’t get anything at all. If I read the file as a String, I will get all the PHP code. What am I doing wrong?

Thanks in advance for any help.

Regards, Matteo

+4
source share
3 answers

If I read the file as a String, I will get all the PHP code

It seems like it is not running on the server side. Do you host it on a server with PHP installed?

+3
source

Check variable name

  • You are tracking myXML and the XML variable name is myXml
+2
source

Does processXML() really work? Try changing it, as in the following code, and see if you get "Hello!". part is traceable.

 function processXML(e:Event):void { trace('Hi!'); var myXml:XML= new XML(e.target.data); trace(myXML); } 

BTW using a flash debugger can be much more useful to try to guess what went wrong :) Since one comes with Flash Professional it sucks a lot of time I can only recommend the DeMonster Debugger , which saved me a lot of time when working on Flash projects. It also does not hurt to have an HTTP traffic analysis tool, for example Fiddler .

0
source

All Articles