Guest books are a great thing to enhance the online experience your viewers receive. The ability for the viewer to talk to you and others, respond to questions you've raised, comment on your work or just to socialize means a guest book is a must have for most web sites. Let's see how we can build our own guest book with ActionsScript 3.0, XML and PHP.
Introduction
There are two main ways I can think of to power a guest book; the more commonly used MYSQL database driven, or the less common XML type. They both rely on server-side scripting to work, however the advantage that I see from using the XML version, is the simple fact that you need not worry about whether your host supports MYSQL and you also don't have to program in 3 different languages. So what will you gain from reading this tutorial I hear you ask?
- You'll learn how to program in ActionScript 3.0 (which took me a long time to learn...)
- You'll learn how to get data from an XML file and convert it into arrays to work within Flash.
- You'll learn how to use these arrays to populate the text field.
- You'll learn how to program buttons and a scroll bar.
- Finally, you'll also learn how to convert text into xml and send it to a php file where it will be written to the xml file.
Quite a mouth full! Let's get started.
Step 1 - Getting Started
You should already know how to open flash, or at least I hope you do... You can set up flash however you choose, there are no specific requirements for Frame Rate or Stage Dimensions, however, make sure you have set it to "Action Script 3.0". If you want to go ahead and copy me word for word I will show you how mine is set up (how nice).

Step 2 - Stylize
As you can tell from the image below, I have fantastic creative skills! This is the point where we design the guest book, or moving into the modern era, a guest computer or guest phone. I'm sure you'll do a better job in making yours look more professional than mine does, but just for those who are new to flash, I'll quickly run through how I created my unique design.
Select the "Rectangle tool", click on "Properties", set the "Stroke" to be "3" and the "Corner Radius" to be "10". Then click and drag to create your rectangle. Make another smaller one on top of that in a different color, this is where the messages will be displayed. Select the new shape and hit "F8" to convert it to a Movie Clip. Then go to "Filter" and apply a "Drop Shadow". Then draw yet another rectangle off to the side; this is where the input fields will go.

Step 3 - Loading the XML
So we venture into the unknown for the first time! Start by creating a new file with the extension ".xml". Then inside that write the following:
<messages> </messages>
Save the file as "messages.xml" in the same folder as your flash file. Now, back in flash, create a new Layer called "Actions" and hit "F9" to bring up the "Actions Panel". It will be much more beneficial to you if you type in the code I give you by hand rather than copying and pasting it, so by hand type:
var urlRequest:URLRequest = new URLRequest("messages.xml");
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener (Event.COMPLETE,fileLoaded);
urlLoader.load (urlRequest);
This bit of code is setting up a variable called "urlRequest" which is holding the path to our ".xml" file. It then creates another variable called "urlLoader" which will be used to load our file. The "addEventListener" is telling flash to wait until the "url" has been loaded before running the "fileLoaded" function. The final line is just telling the "urlLoader" to load "urlRequest" which is our ".xml" file.
var myXML:XML = new XML(); myXML.ignoreWhitespace = true; var xmlList:XMLList;
These lines create a new variable called "myXML" which is going to store all of the data from our ".xml" file. It then tells the variable to "ignoreWhitespace" which doesn't do much, but it helps with validation. The last line creates a variable called "xmlList" which will store the messages and information which we will extract into arrays.
Step 4 - Arrays
var arrayName:Array = new Array(); var arrayTitle:Array = new Array(); var arrayDate:Array = new Array(); var arrayFull:Array = new Array();
This bit of code is setting up the arrays which will hold all of the data. For now it would be best to keep yours the same as mine so you don't get any errors later. You should note that "Full" is what I have used to represent the long message that the user writes.
function fileLoaded (event:Event):void {
myXML = XML(event.target.data);
xmlList = myXML.children();
This is the function "fileLoaded" which is called when the ".xml" file has been loaded. In the function we give the "myXML" variable the data from the ".xml" file. We then give "xmlList" the data stripped from "myXML" which is everything except from the "messages" holder we wrote earlier. Obviously there is nothing else apart from that so "xmlList" will be empty.
for (var i:int=0; i<xmlList.length(); i++) {
var xmlName:String = xmlList[i].name;
var xmlTitle:String = xmlList[i].title;
var xmlDate:String = xmlList[i].date;
var xmlFull:String = xmlList[i].full;
arrayName.push (xmlName);
arrayTitle.push (xmlTitle);
arrayDate.push (xmlDate);
arrayFull.push (xmlFull);
This is the main part of the function. It goes through the data stored in "xmlList" and places it into different arrays. The code starts with a "for" loop, which is saying: while the variable "i" is smaller than "xmlList.length()', run this code. "xmlList.length()" will be how many people have submitted messages, so if it is equal to 5, this code will run 5 times.
Then, for each attribute (name, title, date and the message) we create a "String Variable" equal to the corresponding attribute inside the "xmlList". The first time the code is run, providing there are some entries, "i" will be equal to 1 and "xmlName" will be equal to which ever name is first in "xmlList". The second time it goes through, "i" will be equal to 2 and "xmlName" will be equal to which ever name is second in "xmlList".
What then happens is that each of the variables is added to the arrays. The value of "xmlName" will be added to "arrayName" by the ".push" method. This means that as the code is run through, all of the names that are stored in "xmlList" are added into the array. The same applies for title, date and full.
if (i == xmlList.length() - 1) {
updateText ();
}
}
}
This is the ending part of the function. It states that if "i" is ever equal to the total amount of entries - 1, run the function "updateText".
Step 5 - Showing the Messages
Now, after that grueling piece of coding, we get to something a little easier, he says...
On a new layer called "textBox" use the "Text Tool" to create an "Input Text" field over the lighter rectangle. Make sure that you select the "Render text as HTML" box under "Properties > Character" and give it an "Instance Name" of "messageText".

Go back to the actions window and underneath all of the code type the following:
messageText.htmlText = "Be the first to post!";
var maximumMessages:Number = 5;
var currentMessages:Number = 0;
function updateText () {
messageText.htmlText = "";
The first line is incase no one has written anything. The variable "maximumMessages" is the amount of messages the we want to be displayed at one time. The "currentMessages" is the last message that has been displayed in the text field. Then we start the function which is called after the arrays have finished being created. The first thing this does is to clear the text field as we don't always want that message to be at the top.
for (var i = currentMessages; i<maximumMessages; i++) {
messageText.htmlText += ("<b><u>Name:</u></b> " + arrayName[i]);
messageText.htmlText += ("<b><u>Title:</u></b> " + arrayTitle[i]);
messageText.htmlText += ("<b><u>Date:</u></b> " + arrayDate[i]);
messageText.htmlText += ("<b><u>Message:</u></b> " + arrayFull[i]);
messageText.htmlText += (".....................................................");
}
currentMessages=i;
}
This is another "for" loop. This time we are using it to populate the "messageText" field. Here we are setting "i" to equal "currentMessages" which at the moment is equal to 0. Then if "i" is less than "maximumMessages" which is equal to 5 we run this code. It will therefore run 5 times.
The first time it runs it will add "Name:" to "messsageText" and then whichever name is in the arrayName array at the place of "i" which will be equal to 0. It will do this for title, date and full before ending with a line of dots to separate the messages. The second time it runs through, "i" will be one greater, so it will add more text with results after the first set in the arrays. At the end we set "currentMessages" to equal "i".
Step 6 - Components
At this point you're probably doing well if you don't have a head-ache. So let's do something easy. Go to "Window > Components" and from the list drag out two "Buttons" and one "UIScrollBar". Position them like so:

Then go to "Window > Component Inspector" and with the left button selected, click on the "label" and rename it "Previous". With the button on the right, rename it "Next". Then define the "Previous" button's instance name as "prevBt", the "Next" button's as "nextBt" and the "UIScrollBar's" instance name as "scroller".
Now, under the "currentMessage=i;" piece of code write the following:
scroller.scrollTarget = messageText;
This tells the "UIScrollBar" to act as a scroller for "messageText", incase there are too many words to fit in the designated space. We now need to check if the buttons are being pressed, so underneath all of the code write:
nextBt.addEventListener (MouseEvent.MOUSE_UP,nextFunc); prevBt.addEventListener (MouseEvent.MOUSE_UP,prevFunc);
This adds a listener to see if the mouse cursor has been released over the buttons (if they have been pressed) and if they have, the listener calls a function which we'll write in the next step.
Step 7 - Coding the buttons
If the "Next" button has been pressed we want the "messageText" to remove what's in it and load the next messages. If the "Previous" button is pressed we want it to load the previous messages. At the bottom of all of the code write:
function nextFunc (event:MouseEvent) {
messageText.htmlText="";
maximumMessages+=5;
updateText ();
prevBt.enabled=true;
}
This is the "Next" function. When triggered, it clears the text field, adds 5 to "maximumMessages", runs the function "updateText" and enables the "Previous" button. By adding 5 to "maximumMessages" and running the "updateText" function, it loads the next 5 messages into the text box because now, "maximumMessages" is equal to 10 and "currentMessage" is still equal to 5 from the last time the function ran. Therefore, this time the text field will display the next 5 messages in the arrays.
function prevFunc (event:MouseEvent) {
messageText.htmlText="";
maximumMessages-=5;
currentMessages-=10;
nextBt.enabled = true;
updateText ();
if (currentMessages<=5) {
prevBt.enabled=false;
}
}
This is the function for the "Previous" button. This again clears the text field, it also subtracts "maximumMessages" by 5 and "currentMessages" by 10. This is so that when the "updateText" function runs, it displays the previous 5 entries. It also enables the "Next" button. If "currentMessage" is less than or equal to 5, the "Previous" button is disabled so that the user can't display false information; there are no messages lower than 0.
Just under "function updateText () {" write:
if (arrayName.length <= maximumMessages) {
maximumMessages = arrayName.length;
nextBt.enabled = false;
}
if (currentMessages < 0) {
currentMessages = 0;
maximumMessages = 5;
nextBt.enabled = true;
}
The first "if" is checking if the total number of messages is less than or equal to the maximum. If this is the case, we are displaying the last entry and don't want the user to be able to click the "Next" button, so we disable it. It also makes "maximumMessages" equal the total amount of messages so that we do not display extra unneccesary information.
The second "if" is checking if we have gone into minus numbers. If we have, it defaults back to the start and displays the first 5 entries. Also after this code:
if (i == xmlList.length() - 1) {
updateText ();
}
add the following:
if (i > 4 ) {
nextBt.enabled = true;
}
This is checking if there are more than 5 entries. If there are then we enable the "Next" button. Remember that it's 4 because "i" starts at 0 not 1. Finally, at the top enter the following:
nextBt.enabled = false; prevBt.enabled = false;
This is disabling both buttons.
Step 8 - First Test
Okay, open your ".xml" file and type:
<message> <name>Chris</name> <title>Hello</title> <date>7th</date> <full>this is very complicated =-(</full> </message>
Type it between the tag we wrote earlier, so the whole ".xml" file should only contain:
<messages> <message> <name>Chris</name> <title>Hello</title> <date>7th</date> <full>this is very complicated =-(</full> </message> </messages>
Save the ".xml", then test the flash file and you should see this:

Step 9 - Submit Boxes
Now that we have the first part working, without a break, let's steam into the second section.
It's time to create the area that the user fills in to submit a message. Use the "Text Tool" and create 4 "Static Text Fields" saying "Post a Message", "Name:", "Title:" and "Message:".
Then create 3 "Input Text Fields" and put one next to each element that you want to be filled in. Be sure to make the "Message:" input box larger than the others.
Select the text field where the user will enter their name and give it an "Instance Name" of "inputName". Do this for the title and message boxes, giving their Instance Names "inputTitle" and "inputFull". On all of my three boxes I have selected the "Selectable" and "Show border around text" boxes. Then, open the "Components" panel again and drag out another Button. This time open the "Component Inspector" panel and change its "label" to "Submit" and its "enabled" to false. Give it an Instance Name of "submitBt".

Step 10 - Setting Up Variables
inputName.text = ""; var newName:String = ""; inputTitle.text = ""; var newTitle:String = ""; inputFull.text = ""; var newFull:String = "";
Place this code under all of your other code. This is saying that each of the "Input Fields" which we created in the previous step are blank. It's also creating a variable for each element and specifying it as a "String" with the value of nothing.
function onEnterFrame (ev:Event):void {
if (inputName.text != "" && inputTitle.text != "" && inputFull.text != "") {
submitBt.enabled = true;
}
}
Place this function after all of the code. This function is checking that all of the "Input Fields" contain text. "!=" means does not equal and "&&" is saying "and". So the function is saying: if all of the "Input Fields" are not blank (meaning that the user has filled them in) enable the "submitBt" button. Now we need to be able to call this function all of the time so we need another listener.
addEventListener (Event.ENTER_FRAME, onEnterFrame);
This is saying that every time flash enter the frame (which for me is 30 times a second) call the "onEnterFrame" function.
Step 11 - Date
Now that the submit button is active we need to check if it's been clicked, so we need another listener.
submitBt.addEventListener (MouseEvent.MOUSE_UP,sendData);
When released, this listener will call the function "sendData", so now we need to write the function.
function sendData (event:MouseEvent):void {
var dateToday:Date = new Date();
var thismonth:uint = dateToday.getMonth();
var month:Array = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var dateStr:String = (dateToday.getDate()+" "+month[thismonth]+" "+dateToday.getFullYear());
The first line is opening the function. We then set "dateToday" as a variable and if I then immediately trace "dateToday" it would show "Fri May 5 10:07:32 GMT+0100 2009".
The next line sets the variable "thismonth" as the number which is equal to the current month stored inside "dataToday" As we're currently in May which is the 5th month, if I traced "thismonth" it would reply 4, because it starts at 0, not 1. We then create a new array, storing all of the months in order. Then the "dateStr" is going to store the final date which will be displayed on the guest book.
"dateToday.getDate()" extracts the integer of the current day, so for the 5th, it will extract 5. Then we put in the value of the "month" array that is equal to "thismonth", so it swaps a number for a string of the month. Then the "getFullYear()" extracts the current year in 4 digit format. So if we now trace "dateStr" we get "5 May 2009".
Step 12 - Creating new XML
Now that the user has hit submit, we need to transform the details into xml format so they can be written to the ".xml" file.
newName = inputName.text; newTitle = inputTitle.text; newFull = inputFull.text;
This is turning the variables we defined earlier to equal what the user has entered into the boxes.
var newItem:XML = XML("<message><name>" + newName + "</name><title>" + newTitle + "</title><date>"+ dateStr+ "</date><full>" + newFull + "</full></message>");
This daunting piece of code is creating a new variable called "newItem" which is going to store xml data. We then set it to equal an xml formatted string. We start the string with "<message>" which is going to hold all of the details for the user. We then put in the Name, Title, Date and Full variables that we created before, closing it with "</message>".
myXML.appendChild (newItem);
We are now using "appendChild" to add a "newItem" to the "myXML" which is storing all of the information for the xml file.
Step 13 - Sending The XML.
Now that "myXML" is updated with the new message we need to send it to php.
var request:URLRequest = new URLRequest("messages.php");
request.data = myXML;
request.contentType = "text/xml";
request.method = URLRequestMethod.POST;
Here we are creating a new variable called "request" which is holding the location of our php file. We haven't created this file yet, but I can tell you what we will call it (lucky you!). We'll save it in the same folder as all of our files and call it "messages.php". The next line is telling the "request" that it's sending off the information inside "myXML". We are then telling it that this data is in "XML" format and that we are using "post" to send the data.
var loader:URLLoader = new URLLoader( ); loader.load ( request ); loader.addEventListener ( Event.COMPLETE, loaderDone ); }
Now we are creating a new "loader" to handle the sending of the data, just like earlier when we were receiving the data. We add a listener to check if the data has been sent and if so, it triggers the "loaderDone" function.
Step 14 - Refresh Flash.
Before we move into php there is one last thing we must do inside flash:
function loaderDone (evt:Event):void {
arrayName = [];
arrayTitle = [];
arrayDate = [];
arrayFull = [];
inputName.text = "";
inputTitle.text = "";
inputFull.text = "";
submitBt.enabled = false;
maximumMessages = 5;
currentMessages = 0;
messageText.htmlText = "";
urlLoader.load (urlRequest);
}
This function is clearing the arrays, clearing the Input Text Fields and clearing the messages from the message box. It is also telling "urlLoader" to reload the xml file. This will then trigger the guest book to go back to the start, reload the xml file which has our new entry, populate the arrays and display the first 5 messages once again.
Step 15 - Moving to PHP
Now that we've finished in flash save it and publish the new version. Open up a new php file called "messages.php".
<?php
if (isset($GLOBALS["HTTP_RAW_POST_DATA"])){
$xml = $GLOBALS["HTTP_RAW_POST_DATA"];
$file = fopen("messages.xml","wb");
fwrite($file, $xml);
fclose($file);
}
?>
This code creates the variable "xml" and assigns it the value of the data that has been sent from flash. It then creates the "file" variable which stores the location of the xml file. "fopen" tells php to open the file, "fwrite" then uses "file" to write the contents of the variable "xml" into it. "fclose" then closes the xml file with the new message safely stored in it, ready to be read by the flash guest book once again.
Conclusion
Finally, upload the files onto your server! Remember these will not work on your hard drive unless you have php installed. Locate the guest book and see if it works, hopefully it will! Thanks for your time, I hope you learned something useful!














User Comments
( ADD YOURS )JoeK May 6th
cool post, but using an object array would be simpler, no?
( )JoeK May 6th
missed in my previous message…
but a simpler way to do the XML, is create an XML
var xmlLoader: URLLoader = new URLLoader();
var xmlData: XML = new XML();
var xmlArray: Array = new Array();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest(”xml/menu.xml”));
function LoadXML(e:Event):void
{
trace(”XML File Loaded”);
xmlData = new XML(e.target.data);
for (var i in xmlData.item)
{
xmlArray.push({name:xmlData.item[i].name, title:xmlData.item[i].title, date:xmlData.item[i].date, full:xmlData.item[i].full});
}
trace(xmlArray); // will trace out eg. [Object],[Object] etc.
}
you could then call the array with xmlArray[i].name / xmlArray[i].title / xmlArray[i].date / xmlArray[i].full
( )JoeK May 6th
another,
obviously in my example code, replace any reference to “item” with the name of your node in your xml. in your case it would be “message”
JoeK May 7th
you can now find a downloadable example of the above code at my new blog:
http://wwat.posterous.com
Mike May 6th
Great post, I could see this being useful for a number of different things. Good comment JoeK
( )chrisberthe May 6th
Covered quite a bit in this tutorial, great stuff. Thanks
( )Dario Gutierrez May 6th
Nice tutorial very well explained.
( )CgBaran Tuts May 6th
Great tutorial thanks
( )Yann May 6th
Very, very well explained!
( )More
Diego SA May 6th
Cool! But I’d like to know how to block up bad words. I wouldn’t be happy to see someone posting bad words.
( )lufutu May 6th
Any emoticon for this ?
( )UPrinting.com Printing Services May 6th
What an excellent tutorial! I would really love to learn how to program in Action Script. It will take me a good amount of practice though, but I’m keeping my fingers crossed! Thanks for sharing this, keep up the wonderful work.
( )keruchan May 7th
thankz for the tuts, gonna try it soon
( )Pete May 7th
Really nice tutorial. I’m a new at flash and this is easy to follow, very well explained.
Thanks.
( )Justifier May 7th
Is it possible to update the XML file WITHOUT the use of PHP?
( )JoeK May 7th
unfortunately flash has never really allowed you to write directly to a file, so some kind of intermedium has to actually do the writing of files.
the only exception to this now, iirc, is developing in AiR.
( )최성조 May 7th
Thank you .. ^.^
( )Deoxys May 8th
Don’t you have initialize the variable “dateStr” outer the function? Because when you only declare it within the sendData-Function it would give an error at the newItem variable.
( )Deoxys May 8th
BTW: When ends the sendData-Function? I can’t see any right brace…
( )Janae May 8th
I can’t get the file to open on my computer. I download the source files and try to open the XMLGuestbook.fla file in my Adobe Flash CS3 program and it gives the error “unexpected file format”. ?????
( )JoeK May 8th
The file was created in CS4 and not saved out as a legacy format. CS3 cannot open CS4 .flas.
( )Shane May 8th
You don’t have Flash CS4 ‘Janae’
( )Janae May 9th
Oh ok, thanks Joe, I was wondering if that was the issue, but the “unexpected file format” error kind of threw me…
I do have CS4 Flash ‘Shane’, I just haven’t upgraded yet.
( )Michael Pope May 12th
Hello,
GReat Tutorial! Two questions: 1) my previous button is not loading, is this because i have 5 xml messages but i do not yet have 10?
2) how do you have the most recent message load first when landing on the page?
I hope you don’t mind helping further, this tut was very helpful!
( )David May 14th
Great tutorial!
But how do make so that the most recent messages shows first. Now, the messages that submits lands after eachother, instead of before eachother.
?
( )You understand what i mean
Russ May 19th
David,
I think you should be able to do an xmlList.reverse(); on the array after all the previous messages are loaded or before they are written out on the screen. Just have to make sure that the new messages aren’t then written to the array in the wrong order.
( )David May 19th
Hi Russ,
Can you make an example for the codes above?. I’m quite new at this, and I’m really thankful for all help I can get.
Best Regards!
Martin May 25th
I’m also looking for a way to make the new messages show up on top. Would be great to have a code for that!
rrspyke June 6th
Cs4 is not recognizing the reverse(); coding.
samson May 19th
Great work! Really appreciate your effort.
( )SoulFire86 May 20th
Exactly the tut I was looking for, thanks!
( )SoulFire86 May 20th
Urgh, now I’m done with everything and uploaded to server, etc. But when I try to post a message, it just clears that original message but nothing is changed within the XML file and thus nothing show up in the guestbook.
Anyone know why this might be?
Thanks!
-Soulfire86
( )Frogger May 22nd
check the permissions on your xml file allow anyone to write to it
( )Uffe Pep July 11th
I found this to only be so in firefox… Switching to Private Browsing (under functions in firefox) and back again solved this problem. Weird!
Frogger May 22nd
is there anyway to save the messages in the xml? or if there’s any other way you can delete any spam comments.
Awesome tut, thanks
( )Chris May 26th
Hi everyone, If you liked this tutorial I have just started a video tutorial site screen-tuts.com so come vist sometime =-)
( )David May 26th
How do you get the most recent messages to land first on the xml document? As it is now, they land after eachother? Where should we type the specific code; like xmlList.reverse(); that someone posted before on this page?
Happy to get this right!
Best regards
( )Varg May 31st
I ran into a small snag when i tested this. It seems that some messages delete others and replace them. Can this be avoided ?
( )Kev June 4th
reversing with xmlList.reverse(); doesn’t work it keeps poping out a compiling error. How do I fix this?
( )Dod June 4th
Hi, just found your guestbook guidelines and have just started to follow it. Created my messages xml but I am not sure where I add the info below. All your entries have line numbers starting at 1. therefore I wasn’t sure if I just keep adding to the actions for actions layer. Also not sure where I type the code that follows. Any advice would be great.
1. var myXML:XML = new XML();
( )2. myXML.ignoreWhitespace = true;
3. var xmlList:XMLList;
rrspyke June 6th
Hi there. Great tutz…but enquiring minds want to know…
How do we reverse the order of the posts. It would be so darn helpful to a lot of us to have this ability in the guestbook.
I think your method is excellent, and really don’t want to work out a whole other guestbook tutorial just for one piece of information.
So pleasepleaseplease I pleadpleadplead for everyone here….how do we reverse the order.
Thanks oh Wise One.
( )Roy Arwas June 8th
keeps saying right brace before end of programme what does that mean? :/ can i send you my script somehow? and can u email to me so i can know whteher u cud help me or not?
( )XMLAS3 June 9th
TypeError: Error #1088: The markup in the document following the root element must be well-formed.
at tut_vg_fla::MainTimeline/fileLoaded()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
I have this message in OUTPUT tab. What is wrong? And on the stage does not work.
( )Drake June 12th
Hi! First of all, thanks for this amazing tut
But I have a problem… When I do the Step 8 (the first test), I put all that text into the “messages.xml” file, and then I go to Test Movie…
But then, all the text is displayed in one single line, not in multiple lines like your example (http://flashtuts.s3.amazonaws.com/017_XMLGuestBook/5.jpg)
Here’s a pic from my try: http://i42.tinypic.com/2e1fv69.jpg (I’ve translated everything, cause I’m from Argentina, so I apologize for my bad english)
I don’t know what I’m doing wrong… I hope anyone can help me, I’d really appreciate that
Thanks! ^_^
( )5000 June 13th
HI
Try to set the textbox multiline(properties/paragraph)
( )Drake June 13th
Oh, God
I’m so stupid… xD!
Yeah, that was the problem, now it’s solved
Thanks a lot for taking your time to help ^^
Elagbariel June 17th
Great tutorial, thank you so much for sharing…
I have 2 questions, the first one has been addressed before, How can I reverse the order of the list in order to show the most recent first?, the second one is if the Guest book suppose to start with something on it or just a blank space for the first guest to input his comments?, everything went well I just keep seeing the name , title , date and message field every time, I even deleted the entries and got an empty name, title, date and message field, does anybody knows what I’m doing wrong? thanks for you help.
( )Dave June 17th
This maybe a really dumb question but…
( )How do i now use this on a website?
I have my own and wanted this guestbook.
However, i have no idea on how to incorporate it with my website. Any ideas?
Chris June 19th
Ok, I have read all of the comments, sorry for not being on this for a while. I am going to try and create a part 2 to this tutorial covering how to reverse the order (after many requests…) Filtering certain words and adding emoticons, plus others if i can think of any, I will also save the file for .cs3 rather than .cs4 sorry for not doing this before.
Chris
( )Caselove November 17th
did you do the 2nd tutorial? where can I find it? I would like to know: how to reverse the order. of the comments.. oh, and thank you sooo much for the help! I don’t know what I would have done without you!
( )rekoharlem June 20th
hi thx 4 that tuto…but i got a question…how i can make the new message is the first in the messanger, and not the last…..sry 4 my bad english
i hope you cann help me
( )Matthew Shettler July 3rd
Yeah, just replace appendChild with prependChild.
While appendChild adds to the end of an XML, prependChild adds to the beginning. I had to re-read the flash help three or four times before I spotted it, but it’s there! (^__^)
( )Constantinos June 29th
Great tutorial indeed!
Could I ask you, whether we need to communicate with asp.
( )Does URLRequestMethod.POST works the same since we mention URLRequest(”messages.asp”) ?!
Matthew Shettler June 30th
Hi, would you mind posting a step (e.g. 14.5) that shows the entire actionScript file? I’m working on CS3 and so cannot open the CS4 source file to look at the actions layer; I need to troubleshoot to find out why the guestbook isn’t working for me.
( )Matthew Shettler June 30th
I downloaded the Flash CS4 demo to get at the code. However, I still can’t get the php function to work, neither on MAMP or my server. Something is up. Anyone have suggestions? Did anyone have this issue and then solve it?
Also, here is the full actionscript for all our CS3-using compatriots:
// Loading the XML var urlRequest:URLRequest = new URLRequest("messages.xml"); var urlLoader:URLLoader = new URLLoader(); urlLoader.addEventListener (Event.COMPLETE,fileLoaded); urlLoader.load (urlRequest); // Setting up the XML var myXML:XML = new XML(); myXML.ignoreWhitespace = true; var xmlList:XMLList; // Setting up the data holder arrays var arrayName:Array = new Array(); var arrayTitle:Array = new Array(); var arrayDate:Array = new Array(); var arrayFull:Array = new Array(); // Disabling 'Next' and 'Previous' Buttons nextBt.enabled = false; prevBt.enabled = false; // Populating the Arrays with data from XML function fileLoaded (event:Event):void { myXML = XML(event.target.data); xmlList = myXML.children(); for (var i:int=0; i 4 ) { nextBt.enabled = true; } } } // Populating the Text Field to display Messages messageText.htmlText = "Be the first to post!"; var maximumMessages:Number = 5; var currentMessages:Number = 0; function updateText () { messageText.htmlText = ""; if (arrayName.length < = maximumMessages) { maximumMessages = arrayName.length; nextBt.enabled = false; } if (currentMessages < 0) { currentMessages = 0; maximumMessages = 5; nextBt.enabled = true; } for (var i = currentMessages; iName: " + arrayName[i]);
messageText.htmlText += ("Title: " + arrayTitle[i]);
messageText.htmlText += ("Date: " + arrayDate[i]);
messageText.htmlText += ("Message: " + arrayFull[i]);
messageText.htmlText += (".....................................................");
}
currentMessages=i;
scroller.scrollTarget=messageText;
}
// Checks if 'Next' or 'Previous' buttons are being pressed
nextBt.addEventListener (MouseEvent.MOUSE_UP,nextFunc);
prevBt.addEventListener (MouseEvent.MOUSE_UP,prevFunc);
// 'Next' Function
function nextFunc (event:MouseEvent) {
messageText.htmlText="";
maximumMessages+=5;
updateText ();
prevBt.enabled=true;
}
// 'Previous' Function
function prevFunc (event:MouseEvent) {
messageText.htmlText="";
maximumMessages-=5;
currentMessages-=10;
nextBt.enabled = true;
updateText ();
if (currentMessages< =5) {
prevBt.enabled=false;
}
}
// Sets up the variables to store the users name, title and message
// Also makes sure that the input Fields are blank
inputName.text = "";
var newName:String = "";
inputTitle.text = "";
var newTitle:String = "";
inputFull.text = "";
var newFull:String = "";
// Check if the INput Fields have been typed in
function onEnterFrame (ev:Event):void {
if (inputName.text != "" && inputTitle.text != "" && inputFull.text != "") {
submitBt.enabled = true;
}
}
// Calls 'onEnterFrame' function every time flash enters the frame, 30 times a second
addEventListener (Event.ENTER_FRAME, onEnterFrame);
// Checks if 'submitBt' is being pressed
submitBt.addEventListener (MouseEvent.MOUSE_UP,sendData);
// 'sendData' function
function sendData (event:MouseEvent):void {
//Creates the date
var dateToday:Date = new Date();
var thismonth:uint = dateToday.getMonth();
var month:Array = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var dateStr:String = (dateToday.getDate()+" "+month[thismonth]+" "+dateToday.getFullYear());
// Puts user info into variables
newName = inputName.text;
newTitle = inputTitle.text;
newFull = inputFull.text;
// Creates new xml code with user data
var newItem:XML = XML("" + newName + "" + newTitle + ""+ dateStr+ "" + newFull + "");
// Adds new xml code to origional xml code 'myXML'
myXML.appendChild (newItem);
// Created a new request for the php file
var request:URLRequest = new URLRequest("messages.php");
request.data = myXML;
request.contentType = "text/xml";
request.method = URLRequestMethod.POST;
// Sends the xml data to php
var loader:URLLoader = new URLLoader( );
loader.load ( request );
loader.addEventListener ( Event.COMPLETE, loaderDone );
}
// Reloads to guestbook to diplay new info
function loaderDone (evt:Event):void {
arrayName = [];
arrayTitle = [];
arrayDate = [];
arrayFull = [];
inputName.text = "";
inputTitle.text = "";
inputFull.text = "";
submitBt.enabled = false;
maximumMessages = 5;
currentMessages = 0;
messageText.htmlText = "";
urlLoader.load (urlRequest);
}
( )Uponx July 4th
I’m getting this when I test the movie:
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file:///H|/Documents%20and%20Settings/User/Desktop/Gallery%20Attempt/messages.php
at Untitled_fla::MainTimeline/sendData()
I’m using CS4. What should I do?
( )Ludd November 13th
I had the same error . 2032 error and 2044 error is when you misstype your file name!
( )Uponx July 4th
I have managed to solve the above problem. However, when I’m hitting submit the messages are not appearing.
When I edit the XML file, the messages appear but are all condensed into one line.
( )zed July 7th
Expecting right brace before end of program ?
HELP PLEASE
( )meysam July 9th
thanks …
( )Uponx July 12th
When it expects a right brace before the end of program, add } before the end.
( )chris July 18th
thanks
but it’s not updating messages until you restart the page.
( )sonic July 22nd
for those who still searching for a way to reverse the xml entries…
its quite simple. search for the part where you pu your xml entries in the arrays. just change the .push() method to .unshift()
it will read the last entry first and then second last and so on….
anybody knows how to update the messages without restarting the page. have found no way yet….
( )chris July 24th
replace the last line of code
“urlLoader.load (urlRequest)”
with this line of code
var req:URLRequest = new URLRequest( “messages.xml” );
( )req.method = URLRequestMethod.POST;
req.data = true;
urlLoader.load (req);
Raydowe November 12th
syntax error
( )Mitch July 24th
I think you forgot to mention that once the xml file is on your server you need to change is CHOD permissions to 777 inorder for the php file to have access to it. You can do this using your ftp browser. Apart from that its a great tut, although Cs3 source files would have been cool.
Cheers
( )Dominik August 2nd
How can i get the new messages to show up first and not underneath ???
( )Dominik August 2nd
Also, The english date is showing up the wrong way. It should be month/date/year and not date/month/year. How can I reverse the month and the date?
Thank you so much !
( )Fabrice August 2nd
Hello,
When I’m testing my file i see 5 blank entries in the message box. How can i remove them and only text in it if somebody actually write something.
Thanks,
( )Lac August 3rd
Hi!
( )Thank you, Chris for this really usefull tutorial, and for the solution for the reload-problem !!!
I also want to thank Matthew Shettler for the prepedChild command (it’s reversing the order of the messages).
Thank you, guys!
Lac August 4th
Hi, again!
( )I just reallized, that something’s wrong with my updateText() function, couse when the amount of the messages goes above 5, the nextBt don’t show up. (oh yes, i used their .visible function…).
Can somebody help me?
drakmar August 5th
Cannot open the flash file – unexpected file format.
Any ideas why?
Just testing this out to see how it works…..
( )Lac August 5th
It’s CS4 format, as it was mentionned above… Read the tutorial, and follow the instructions. I also suggest, that you should read the comments too, couse there are a lot useful things there…
( )David Moreen August 23rd
Man I suck at flash. It is that one program that I can’t do! I can do PHP… HTML… CSS, I even learned some objective C, but I can not get Actionscript. The tutorial was well, I liked how you explained what the code did after you have us type it out.
( )Michael Benin September 12th
Thank you.
( )David September 23rd
David
( )David September 23rd
i liked this tutorial.nice one
( )Julio Villa September 25th
Hi did this entire tutorial….put it on my server but nothing happens when i input a message. check it out at redroombeats.com/guest.html……the server is php ready also, i’ve done other tutorials which worked fine, but i really want this to work.
( )Lac October 1st
Hi!
( )I can’t tell what’s the problem. But if you could share the source file and the files you use, i can take a look at it… I can promise you nothing, but to check it . . .
Joel Santos October 27th
I have same problem. Done everything well and such and then get the XML file to be 777 permission but still… PHP isn’t writing on the XML, xml still blank!
Dave October 27th
Maybe I should write a tutorial that doesn’t work and get paid too yeah?
( )Raydowe November 12th
Thist tutorial not work..
PHP not writing any data to XML… a click to submit but nothing happend.. only reload
( )Lac November 13th
I don’t really know whats your problem, it perfectly worked for me . . .
( )Make sure your server allowes php to work.
Ludd November 13th
It was a good tutorial. Learned a lot. I didn’t like the design so i build a whole new concept from your tutorial. I still need to add 2 elements to the guestbook like a scroller and a message that lets the guest know the message has been successfully send or not. But other than that it works like a charm.
http://www.modderfokker.eu/deploy/guestbook.html
php file worked perfectly online but not on Xampp on my mac. I will be including a cms to alter the colors and text , and manage the messages.
have fun with this tutorial, I surely did.
( )Ludd November 14th
http://www.modderfokker.eu/deploy/guestbook.html
scrollbar working perfectly now! Test if you like!
( )ludd November 16th
UPDATE: BUGS IN SCRIPT
I did find some odd bugs mainly because I was teting it extensively.
A) Reloading File in Memory:
Sometimes when reloading the changed xml file – the swf file tends to reload the xml file in memory without the recent updates.
B) Simultaniously using the guestbook:
If two or more people are having the same page open at the same time, it can cause messages to be erased or overwritten. This is because the actionscript stores a copy of the loaded xml file( in myXML) even if it has been updated while the user is stull writing his or her message. When this user post his message his or her copy will override any changes made by another user wich also had the page open in the same timeframe.
I did correct these bugs in my own application.
Tip1: prior to posting your new message you can reload/ reimport the xml file. When this is loaded you can add (append) the input values to it.
Tip2: I added a unique id variable to the end of the xml and the php file. This seemed to work now for my application;
‘guestbook.xml?id=’ + uniqueValue + ‘ ” ‘ ;
‘message.php?id=’ + uniqueValue + ‘ ” ‘ ;
using the date class you can construct a unique value;
After these changed my application did work correctly!
( )