Flash based XML Comments without a mySql database.
November 15th, 2008
Whilst working on a project recently I discovered an excellent and fun way to add a custom comments page, without the need to have a sometimes costly mySql database. The file is totally driven by XML and the data, once submitted by the user is rewritten by a small PHP script. It is very light weight and very easy to customise.
The document class of the flash file firstly loads an xml file which carries the data of any previous comments by loading it with the loader:
-
private var xmlCom:XML;
-
private var xmlUrlCom:URLRequest = new URLRequest("Comments.xml");
-
private var loaderCom:URLLoader = new URLLoader();
-
private var xmlURLReq:URLRequest = new URLRequest("savexml.php");
The loader is loaded and via a couple of text boxes, the text from the xml file is added to the stage. Nice and easy. Now comes the smart part. The comment box is waiting for data to be added and once the submit button is clicked, this data is added to the original xml via the insertChildAfter() method.
-
xmlCom.insertChildAfter(xmlCom.comments[0], newNode);
-
xmlURLReq.data = xmlCom;
-
xmlURLReq.contentType = "text/xml";
-
xmlURLReq.method = URLRequestMethod.POST;
-
var xmlSendLoad:URLLoader = new URLLoader();
-
xmlSendLoad.addEventListener(Event.COMPLETE, onComplete);
-
xmlSendLoad.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
-
xmlSendLoad.load(xmlURLReq);
This data is then sent to the PHP file via the URLRequest() which in turn writes it back into the original xml file ready for when the swf is next loaded. In the version I have uploaded here I have also made the comment snippets draggable, but they could easily be adapted for a static comments column as you see in blogs etc.
So easy but such an effective result.
Fla and source files including php script
Categories: XML | Tags: comments page, php, XML | 3 Comments



![Validate my RSS feed [Valid RSS]](http://www.ultravisual.co.uk/blog/images/valid-rss.png)




