Flash CS3 - XML Guestbook (AS3)
XmlCs3GuestBook.as
package {
import flash.display.MovieClip;
import flash.display.Loader;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.*;
import flash.text.TextField;
import flash.text.TextFieldType;
import fl.controls.ScrollBar;
import fl.controls.UIScrollBar;
import flash.text.TextFieldAutoSize;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.URLRequestMethod;
public class XmlCs3GuestBook extends MovieClip {
var loader:Loader = new Loader();
var xmlData:XML= new XML();
var xmlLoader:URLLoader = new URLLoader();
var TxtMessges:TextField = new TextField();
var myScrollBar = new UIScrollBar();
var MSGCounter:int = 1;var form = new MovieClip();
public function XmlCs3GuestBook():void {
stage.frameRate=30;
xmlLoader = new URLLoader( new URLRequest("guestbook.xml") );
xmlLoader.addEventListener(Event.COMPLETE, gotXML);
}function gotXML(evt:Event):void {
xmlData = XML(xmlLoader.data);
for each (var item:XML in xmlData..Guest) {TxtMessges.appendText("Message "+MSGCounter++ +"\n");
TxtMessges.appendText("Name - ");
TxtMessges.appendText(item.name.toString());
TxtMessges.appendText("\nEmail - ");
TxtMessges.appendText(item.email.toString());TxtMessges.appendText("\nMessage - ");
TxtMessges.appendText(item.message.toString());TxtMessges.appendText("\nTime - ");
TxtMessges.appendText(item.time.toString());
TxtMessges.appendText("\n------------------------------------------------------------------------\n");
TxtMessges.appendText("\n\n");}
TxtMessges.y=40;
TxtMessges.width =380;
TxtMessges.height=300;
TxtMessges.border = true;
TxtMessges.mouseWheelEnabled = true;
TxtMessges.wordWrap=true;myScrollBar.scrollTarget = TxtMessges;
myScrollBar.y=TxtMessges.y;
myScrollBar.x=TxtMessges.width;
myScrollBar.height= TxtMessges.height;
addChild(TxtMessges);
addChild(myScrollBar);xmlLoader.removeEventListener(Event.COMPLETE,gotXML);
createAddDetailsForm();
}function createAddDetailsForm() {
var BoxBG = createRectangle(400,340,0xF8F8F8,.9);
var AddMsgButton = createRectangle(80,20,0xCCCCCC,1);
AddMsgButton.name="AddMsgButton";var TextAddMsgButton= new TextField();
TextAddMsgButton.autoSize = TextFieldAutoSize.LEFT;
TextAddMsgButton.selectable=false;
TextAddMsgButton.text = "Add Message";AddMsgButton.buttonMode=true;
AddMsgButton.addEventListener(MouseEvent.CLICK,AddMsgButtonClickHandler);AddMsgButton.addChild(TextAddMsgButton);
AddMsgButton.x=BoxBG.width- AddMsgButton.width;
AddMsgButton.y=BoxBG.height- AddMsgButton.height;
AddMsgButton.mouseChildren=false;
BoxBG.addChild( AddMsgButton);var LabelName = new TextField();
var LableEmail= new TextField();
var LabelMessage = new TextField();
var LabelTime = new TextField();var InputName = new TextField();
var InputEmail = new TextField();
var InputMessage = new TextField();
var InputTime = new TextField();LabelName.text = "Name" ;
LableEmail.text="Email" ;
LabelMessage.text ="Message" ;
LabelTime.text = "Time" ;
LabelName.y=50;
LableEmail.y= 100;
LabelMessage.y = 150;
LabelTime.y = 220;LabelName.x=50;
LableEmail.x= 50;
LabelMessage.x = 50;
LabelTime.x = 50;InputName.y = 50;
InputEmail.y = 100;
InputMessage.y = 150;
InputTime.y = 220;InputName.x = 100;
InputEmail.x = 100;
InputMessage.x = 100;
InputTime.x = 100;InputName.width = 200;
InputEmail.width = 200;
InputMessage.width = 200;
InputTime.width= 200;InputName.height = 20;
InputEmail.height = 20;
InputMessage.height = 50;
InputMessage.wordWrap=true;
InputTime.height= 20;InputName.type = TextFieldType.INPUT;
InputEmail.type = TextFieldType.INPUT;
InputMessage.type = TextFieldType.INPUT;/*
InputName.border = true;
InputEmail.border = true;
InputMessage.border = true;
InputTime.border = true;*/InputName.background = true;
InputEmail.background = true;
InputMessage.background = true;
InputTime.background = true;BoxBG.addChild(LabelName);
BoxBG.addChild(LableEmail);
BoxBG.addChild(LabelMessage);
BoxBG.addChild(LabelTime);
BoxBG.addChild(InputName);
BoxBG.addChild(InputEmail);
BoxBG.addChild(InputMessage);
BoxBG.addChild(InputTime);var SendButton = createRectangle(80,20,0xCCCCCC,1);
var TextSendButton= new TextField();
TextSendButton.autoSize = TextFieldAutoSize.LEFT;
TextSendButton.selectable=false;
TextSendButton.text = "Send";SendButton.x=AddMsgButton.x;
SendButton.y= AddMsgButton.y-SendButton.height-10;SendButton.addChild(TextSendButton);
BoxBG.addChild(SendButton);SendButton.mouseChildren=false;
SendButton.buttonMode=true;
SendButton.addEventListener(MouseEvent.CLICK,SendButtonClickHandler);
SendButton.addEventListener(MouseEvent.CLICK,AddMsgButtonClickHandler);form =BoxBG;
form .y=30-form .height;
addChild(form );
}function createRectangle(Width:int,Height:int,color:Number,Alpha:Number):MovieClip {
var MyRect=new MovieClip();
MyRect.graphics.beginFill(color,Alpha);
MyRect.graphics.drawRect(0,0,Width,Height);
MyRect.graphics.endFill();
return MyRect;
}function AddMsgButtonClickHandler(e:MouseEvent) {
if (form .y==0) {
TweenHandler(form ,form.y,(form.y-form .height)+30,"y");
form.getChildAt(0).getChildAt(0).text="Add Message";
} else {
TweenHandler(form ,form.y,0,"y");
form.getChildAt(0).getChildAt(0).text="Close";
var myDate1:Date = new Date();
form.getChildAt(8).text= myDate1;
}
}function SendButtonClickHandler(e:MouseEvent):void {
if (form.getChildAt(5).text!=""&&form.getChildAt(6).text!=""&&form.getChildAt(7).text!=""&&form.getChildAt(8).text!="") {
var newItem:XML =
<Guest >
<name>{form.getChildAt(5).text}</name>
<email>{form.getChildAt(6).text}</email>
<message>{form.getChildAt(7).text}</message>
<time>{form.getChildAt(8).text}</time>
</Guest>;
xmlData.appendChild(newItem);
callServer(xmlData);/////////////////////////
TxtMessges.appendText("Message "+MSGCounter++ +"\n");
TxtMessges.appendText("Name - ");
TxtMessges.appendText(form.getChildAt(5).text);
TxtMessges.appendText("\nEmail - ");
TxtMessges.appendText(form.getChildAt(6).text);TxtMessges.appendText("\nMessage - ");
TxtMessges.appendText(form.getChildAt(7).text);TxtMessges.appendText("\nTime - ");
TxtMessges.appendText(form.getChildAt(8).text);
TxtMessges.appendText("\n------------------------------------------------------------------------\n");
TxtMessges.appendText("\n\n");
////////////////////////////////////
}
}
function TweenHandler(myObject:MovieClip,Start:Number,Stop:Number,Property:String) {
var myTween:Tween = new Tween(myObject, Property, Regular.easeInOut, Start, Stop, .2, true);
}function callServer(XMLData:XML):void {
var urlRequest:URLRequest = new URLRequest("processXML.php");var urlParams:URLVariables = new URLVariables();
urlParams.xmlVal = XMLData;urlRequest.method = URLRequestMethod.POST;
urlRequest.data = urlParams;var loader:URLLoader = new URLLoader();
loader.load(urlRequest);
}
}
}
Comments
www.vietnamcambodge.com
www.voyagecambodge.info
www.voyagesurcambodge.com
www.voyagesvoyages.info