Guestbook - Flash/PHP/XML

Hi All,

please I am looking at the Flash Guestbook sample file (Flash MX 2004>Samples>HelpExamples>guestbook)

And it didn’t know how the swf connects with the xml thru php.

so I have the ActionScript:

//****************************************************************************
//Copyright (C) 2004 Macromedia, Inc. All Rights Reserved.
//The following is Sample Code and is subject to all restrictions on
//such code as contained in the End User License Agreement accompanying
//this product.
//****************************************************************************

/* 
PHP and Flash example
This example shows you how to create a guestbook using Flash and PHP integration.
*/

stop();

// import the required component classes.
import mx.controls.*;

// define the component instances on the Stage.
var name_ti:TextInput;
var email_ti:TextInput;
var url_ti:TextInput;
var comments_ta:TextArea;
var clear_button:Button;
var submit_button:Button;
var name_label:Label;
var email_label:Label;
var url_label:Label;
var comments_label:Label;

//set color of labels
name_label.setStyle("color", "0xFFFFFF");
email_label.setStyle("color", "0xFFFFFF");
url_label.setStyle("color", "0xFFFFFF");
comments_label.setStyle("color", "0xFFFFFF");

// set the tabbing order for the components
this.name_ti.tabIndex = 1;
this.email_ti.tabIndex = 2;
this.url_ti.tabIndex = 3;
this.comments_ta.tabIndex = 4;
this.clear_button.tabIndex = 5;
this.submit_button.tabIndex = 6;

// set the default form focus to the name_ti TextInput instance, and set the default button to the submit button.
Selection.setFocus(name_ti);
focusManager.defaultPushButton = submit_button;

// when the post_mc or view_mc movie clip's are clicked and released, goto the appropriate named frame label.
post_mc.onRelease = function() {
	this._parent.gotoAndStop("post");
};
view_mc.onRelease = function() {
	this._parent.gotoAndStop("view");
};

// when the clear button is clicked, set the form fields to empty strings.
var clearBtnListener:Object = new Object();
clearBtnListener.click = function(evt:Object) {
	name_ti.text = "";
	email_ti.text = "";
	url_ti.text = "";
	comments_ta.text = "";
};
this.clear_button.addEventListener("click", clearBtnListener);

// when the submit button is clicked, send the form values to the server using a LoadVars object.
var postBtnListener:Object = new Object();
postBtnListener.click = function(evt:Object) {
	// if the name is blank, display an error message using the Alert component.
	if (name_ti.text.length == 0) {
		Selection.setFocus(name_ti);
		Alert.show("Please enter your Name.", "Error", Alert.OK);
		return false;
	}
	// make sure the user has filled in either the email_ti or url_ti TextInput instances.
	if ((email_ti.text.length == 0) && (url_ti.text.length == 0)) {
		Selection.setFocus(email_ti);
		Alert.show("Please enter your Email Address or URL.", "Error", Alert.OK);
		return false;
	}
	// make sure the comments_ta TextArea instance isn't blank.
	if (comments_ta.text.length == 0) {
		Selection.setFocus(comments_ta);
		Alert.show("Please enter your Comments.", "Error", Alert.OK);
		return false;
	}
	
	// if all the required fields have been filled in, create a LoadVars object instance and populate it.
	var send_lv:LoadVars = new LoadVars();
	send_lv.name = name_ti.text;
	send_lv.email = email_ti.text;
	send_lv.url = url_ti.text;
	send_lv.comments = comments_ta.text;
	send_lv.onLoad = function(success:Boolean) {
		// if the comments were sent to the server and you received a response, clear the form fields and display an Alert message.
		if (success) {
			name_ti.text = "";
			email_ti.text = "";
			url_ti.text = "";
			comments_ta.text = "";
			Alert.show("Thank you for your comments.", "Success", Alert.OK);
		} else {
			// else you encountered an error while submitting to the server.
			Alert.show("Unable to process your comments at this time.", "Server Error", Alert.OK);
		}
	};
	// send the variables from Flash to the remote PHP template.
	send_lv.sendAndLoad("http://www.flash2004.com/dev/guestbook/gb_insert.php", send_lv, "POST");
};
this.submit_button.addEventListener("click", postBtnListener);

The Code From the View Page:

//****************************************************************************
//Copyright (C) 2004 Macromedia, Inc. All Rights Reserved.
//The following is Sample Code and is subject to all restrictions on
//such code as contained in the End User License Agreement accompanying
//this product.
//****************************************************************************

stop();

var guestbook_ta:mx.controls.TextArea;

// create an XML object instance which is used to load comments from a remote server.
var guestbook_xml:XML = new XML();
guestbook_xml.ignoreWhite = true;
guestbook_xml.onLoad = function(success:Boolean) {
	if (success) {
		var numEntries = this.firstChild.childNodes.length;
		// loop through each of the entries from the XML packet...
		for (var i = 0; i<numEntries; i++) {
			// create a shortcut to the current child node
			var entry_xml:XMLNode = this.firstChild.childNodes*.childNodes;
			
			/* set local variables for the name, email address, url, comments and timestamp. 
			Since you know the structure of the XML packet, you know the index of each of these child nodes. */
			var name_string:String = entry_xml[1].firstChild.nodeValue;
			var emailaddress_string:String = entry_xml[2].firstChild.nodeValue;
			var url_string:String = entry_xml[3].firstChild.nodeValue;
			var comments_string:String = entry_xml[4].firstChild.nodeValue;
			var datetime_string:String = entry_xml[6].firstChild.nodeValue;
			
			// the "entry_string" variable is used to hold the HTML formatted contents of the current guestbook entry
			var entry_string:String = "<p>";
			entry_string += "<span>"+name_string+"</span><br>";
			
			// if the email address isn't blank, append it to the current entry_string variable.
			if ((emailaddress_string != undefined) && (emailaddress_string.length>0)) {
				entry_string += "<a href=\"mailto:"+emailaddress_string+"\" target=\"_blank\">email</a><br>";
			}
			// if the url isn't blank, append it to the current entry_string variable.
			if ((url_string != undefined) && (url_string.length>0)) {
				// if the first five characters of the URL aren't "http:", set the prefix to "http://".
				var prefix_string:String = (url_string.substr(0, 5) != "http:") ? "http://" : "";
				entry_string += "<a href=\""+prefix_string+url_string+"\" target=\"_blank\">url</a><br>";
			}
			entry_string += comments_string+"<br>";
			entry_string += "<i>"+datetime_string+"</i><br>";
			entry_string += "</p>";
			// draw a horizontal line after each guestbook entry.
			entry_string += "<img src=\"line_gr\"><br>";
			// append each current entry to the current value of guestbook_ta
			guestbook_ta.text += entry_string+"<br>";
		}
	} else {
		trace("error loading XML");
	}
};

// load the guestbook XML entries from the remote server.
guestbook_xml.load("http://www.flash2004.com/dev/guestbook/gb_select.php");

// create a new instance of the TextField.StyleSheet object.
var styleObj = new TextField.StyleSheet();
styleObj.onLoad = function(success:Boolean) {
	if (success) {
		guestbook_ta.styleSheet = styleObj;
	}
};

// load the external style sheet
styleObj.load("styles.css");

And the XML :

<?xml version="1.0" encoding="iso-8859-1" ?>

<guestbook entries="1">
<entry>
	<id></id>
	<name></name>
	<emailaddress></emailaddress>
	<url></url>
	<comments></comments>
	<ipaddress></ipaddress>
	<datetime></datetime>
</entry>
</guestbook>

Please how the PHP file might be?!

Thanks u very much

Greetings