XML Guestbook with PHP

Hi

I just log in here today and found this guest book tutorial. I would say this guestbook is really cool and what I’m looking for. Thanks Flashmatazz

Still I have couple of questions about this guestbook. first, I saw the swf file of the guestbook is about 60kb, I just wondering what make it too big (I mean it’s only contain a few box,button and text right,I think 60kb too big for that)…is there a way to ‘shrink’ the number (at least 20kb or less) ?

second question is, after the swf is load, it load the guestbook.xml content, I have put alot of entries for testing and it would take a while loading them (I’m using dial-up)…is there a way so I could put a percentage preloader or may be a text like ‘loading…’ to tell the viewer the content is being load?

Anyway…It’s a really really nice scripts (I think I could eleborate the function to do many thing else too)

Thanks in advance…

60kb too big for that

I havent looked at it in a while, but components always jack up the file size…

As for the preloader…

I would put a playmovie just before the loading bit,
and then just after the success bit tell the movie to unload/visible = false etc…

I could be wong on both, but thats what I think anyway… :slight_smile:

I’ve thought about that too actually…I’m thinking about replacing the scroll bar with my custome made…

That’s sound intresting…could you please explain more on how to do that ?

I would wait for Flashmatazz to answer (he should know better) but I really appreciate yours Vulcan, Thank you very much!
C:-)

 

// **** Load XML ****************************
//Put a play movie in here.....  it will start playing just as the request is made to load the XML data
myXML = new XML();
myXML.ignoreWhite = true;
receiverXML = new XML();

myXML.onLoad = function(success){
 myXML.contentType = "text/xml";
 if (success){
  this.showXML();
//Put stop/unload movie here once you know the XML file has been loaded.
 }
 else{
  trace("Error loading XML file");
//You could tell a movie to play here saying that there has been a error if you wanted.
 }
}

ok…I think I could figure it out from there…thanks again mate

Hi again…

I’m trying to add an email form inside the add message and edit the main action script like this :

stop();
var currPage = 0;
var showAmount = 10; // set this to the amount of entries you want to view at a time
previous._visible = false;
createMessage._visible = false;
createButton.onRelease = function(){
this._visible = false;
this._parent.createMessage._visible = true;
if (createMessage.nameField.text == “”){
Selection.setFocus(createMessage.nameField);
}
else if (createMessage.messageField.text == “”){
Selection.setFocus(createMessage.messageField);
}
}

// **** Load XML ****************************
myXML = new XML();
myXML.ignoreWhite = true;
receiverXML = new XML();

myXML.onLoad = function(success){
myXML.contentType = “text/xml”;
if (success){
this.showXML();
}
else{
trace(“Error loading XML file”);
}
}
myIdentifier=Math.round(Math.random()10000);
myXML.load(“guestbook.xml?uniq=”+myIdentifier);

receiverXML.onLoad = function(){
this.contentType = “text/xml”;
_root.currPage = 0;
this.showXML();
}
createMessage.closeButton.onRelease = function(){
this._parent._visible = false;
createButton._visible = true;
}
createMessage.sendButton.onRelease = function(){
var myName = this._parent.nameField.text;
var myMessage = this._parent.messageField.text;
[color=darkorange]var myEmail = this._parent.emailField.text;
[/color] if (myName == “”){
this._parent.errorField.text = “please fill out your name”;
Selection.setFocus(this._parent.nameField);
}
else if (myMessage == “”){
this._parent.errorField.text = “please leave a message”;
Selection.setFocus(this._parent.messageField);
}
else {
myXML.firstChild.appendChild(myXML.createElement(“entry”));
myXML.firstChild.lastChild.attributes.myName = myName;
myXML.firstChild.lastChild.appendChild(myXML.createElement(“myText”));
myXML.firstChild.lastChild.lastChild.appendChild(myXML.createTextNode(myMessage));
[color=darkorange]myXML.firstChild.lastChild.appendChild(myXML.createElement(“myEmail”));
myXML.firstChild.lastChild.lastChild.appendChild(myXML.createTextNode(myEmail));
[/color] myXML.sendAndLoad(“processXML.php”, receiverXML);
this._parent._visible = false;
createButton._visible = true;
}
}
XML.prototype.showXML = function(){
myGuestbook.scroll = 1;
myGuestbook.htmlText = “”;
var numItems = this.firstChild.childNodes.length;
var firstItem = numItems - (currPage
showAmount);
if (currPage == 0) previous._visible = false;
var lastItem = firstItem - showAmount ;
if (lastItem<=0) {
lastItem = 0;
next._visible = false;
}
myCount.text = "Total messages: " + numItems;
if (firstItem == lastItem+1) nowShowing.text = "Showing message " + firstItem;
else nowShowing.text = "Showing message " + firstItem + " to " + (lastItem + 1);
for (i=(firstItem-1); i>= lastItem; i–){
myGuestbook.htmlText += “<B>” + this.firstChild.childNodes
.attributes.myName + “</B> wrote:
”;
myGuestbook.htmlText += this.firstChild.childNodes*.firstChild.firstChild.nodeValue + "

";
[color=red]myGuestbook.htmlText += this.firstChild.childNodes*.firstChild.firstChild.nodeValue + “
”;
[/color] }
}
previous.onRelease = function(){
currPage–;
myXML.showXML();
next._visible = true;
}
next.onRelease = function(){
currPage++;
myXML.showXML();
previous._visible = true;
}*

Upload all the files and input made a test,I checked in guestbook.xml and it show this :

[font=Courier New]<?xml version=“1.0”?>[/font]
[font=Courier New]<guestbook>[/font]
[font=Courier New]<entry myName="[color=blue]RinaAzlin[/color]">[/font]
[font=Courier New] <myText>
[color=blue]testing message.[/color]
</myText>[/font]
[font=Courier New] <myEmail>
[color=blue][email protected][/color]
</myEmail>[/font]
[font=Courier New]</entry>[/font]
[font=Courier New]</guestbook>[/font]
[font=Courier New][/font]
[font=Courier New]But the problem is, in the swf file, instead writing myEmail, it repeating mytext content.[/font]

you could view it here.

http://www.ornith.org/~shapa/message.htm

I think the problem is in here

myGuestbook.htmlText += “<B>” + this.firstChild.childNodes.attributes.myName + “</B> wrote:
”;
myGuestbook.htmlText += this.firstChild.childNodes*.firstChild.firstChild.nodeValue + "

";
[color=red]myGuestbook.htmlText += this.firstChild.childNodes.firstChild.firstChild.nodeValue + “
”;
[/color]
[color=#ff0000][/color]
[color=red][color=#000000]And honestly, I don’t really know how to solve this.[/color][/color]
[color=red][color=#000000]Anybody could help me on this ?[/color][/color]
[color=red][color=#000000][/color][/color]
[color=red][color=#000000]Thanks in advance…[/color]

[/color]

Sorry I can’t help you with that because I don’t know jack about XML…

But I like what you have done with it :slight_smile:

We in the same boat Vulcan, I know nothing about XML too :blush: (just start to learn about it since this guestbook) I really really hope Flashmatazz could come up to solve this…

Hi RinaAzlin,

I’ll first have some breakfast and then I’ll get back to you. :stuck_out_tongue:

Ok, instead of using a new textnode, just use a new attribute.

assuming you’ve created an input textfield called myEmail, within the sendButton.onRelease handler:


var myName = this._parent.nameField.text;
var myMessage = this._parent.messageField.text;
// emailfield
var myEmail = this._parent.emailField.text;
// etc.

within the else statement:


myXML.firstChild.appendChild(myXML.createElement("entry"));
// email
myXML.firstChild.lastChild.attributes.myEmail = myEmail;
myXML.firstChild.lastChild.attributes.myName = myName;
// etc/

then within the for loop of the showXML function:


var myName 	= this.firstChild.childNodes*.attributes.myName;
var myEmail = this.firstChild.childNodes*.attributes.myEmail;
myGuestbook.htmlText += myName + " <U><A href='mailto:" + myEmail + "'>[" + myEmail + "</A></U>] wrote:
";
myGuestbook.htmlText += this.firstChild.childNodes*.firstChild.firstChild.nodeValue + "

";

It works! You’re the man Flashmatazz…Thank you very very much…What’s the different between textnode and attribute? And thanks again to you too Vulcan

Well, using the email address as an attribute the XML will look like this:


<entry myName="Flashmatazz" myEmail="[email protected]">
  <myText>Blahblah...</myText>
</entry>

if you’d like the email as a node the XML would look like this:


<entry myName="Flashmatazz">
  <myEmail>[email protected]</myEmail>
  <myText>Blahblah...</myText>
</entry>

However, since we already have a node called ‘entry’ it’s a bit simpler to create an attribute for it to contain the email address, in the same way the ‘name’ attribute is created.

Hope that clears it up a bit.

Thank you very much Flashmatazz, that’s help a lot though I guess I’ve to learn XML from zero…I heard we could save/load images inside flash using XML…do you know any good tutorial on this one ?

Sorry to bother about this again Flashmatazz but regarding my earlier question, is any way to reduce the size of this guest book, In my server it’s indicate the swf file is more than 60kb, I wish to reduce it to at least half of it (30+kb is good enough)

add up to rinaazlin question, can it display ‘loading text’ first before it load XML. The_vulcan’s idea is great, but can it be done in other way? like put some text in flash AS.

Neo-Geo.
you can easily type a text like ‘loading…’ or something inside the text field in the flash file. Just like that and the loaded guestbook.xml content will overwrite it. Off course vulcan suggest would be good too…

Is there any set-up with php and xml on my server before i try it? I can’t seem to get it working. I have the html, php, xml, and the swf on my sever and they dont respond.

Nevermind got it!! Thanks for looking though!