8 Replies Latest reply on Nov 8, 2014 1:12 PM by Ned Murphy

    would someone be willing to check as3 code for a guestbook

    JimmyB29

      Would someone be willing to check out some as3 code for a guestbook? I'm an old person, and can't seem to get it working.

       

      Thanks!

        • 1. Re: would someone be willing to check as3 code for a guestbook
          Ned Murphy Adobe Community Professional & MVP

          If you show the code that is not working and explain what about it does not work you will better your chances of getting some assistance. 

          • 3. Re: would someone be willing to check as3 code for a guestbook
            JimmyB29 Level 1

            Ned suggested that I post the code, so everyone could see it. The SWF works, but the code doesn't. Any help appreciated!

             

            package com.mgraph\

             

             

              //IMPORTS

              import flash.display.Loader;

              import flash.display.MovieClip;

              import flash.display.Sprite;

              import flash.display.StageAlign;

              import flash.display.StageScaleMode;

              import flash.events::EventDispatcher/dispatchEventFunction();

              import flash.events::EventDispatcher/dispatchEvent();

              import flash.events.MouseEvent;

              import flash.events.TextEvent;

              import flash.events.KeyboardEvent;

              import flash.geom.Rectangle;

              import flash.net::URLLoader/onComplete();

              import flash.net.URLRequest;

              import flash.net.URLRequestMethod;

              import flash.net.URLVariables;

              import flash.text.TextFieldAutoSize;

              import flash.text.TextFormat;

             

             

              import com.utils.StringUtils;

              import com.caurina.transitions.Tweener;

             

              import com.pageflip.Page;

              import com.pageflip.PageEvent;

             

              public class Guestbook extends MovieClip {

             

              //PRIVATE VARS

              private var myXML:XML;

              private var frm:TextFormat;

              private var popup_mc:MovieClip;

              private var greySprite:Sprite;

             

             

              private var initPosition:Number;

              private var dy:Number;

              private var initContentPos:Number;

              private var moveVal:Number;

              private var rectScroll:Rectangle;

             

              private var stageWidth:Number;

              private var stageHeight:Number;

             

             

              public function Guestbook(){

              addEventListener(Event.ADDED_TO_STAGE,init);

              }

              private function init(e:Event):void {

              stage.showDefaultContextMenu = false;

              stage.align = StageAlign.TOP_LEFT;

              stage.scaleMode = StageScaleMode.NO_SCALE;

             

              stageWidth = stage.stageWidth;

              stageHeight = stage.stageHeight;

             

              // LOAD THE XML

              var xmlPath:String;

              var xmlLoader:URLLoader = new URLLoader;

              if (root.loaderInfo.parameters.myconfig) {

              // XML PATH FROM HTML flashvars (myconfig)

              xmlPath = root.loaderInfo.parameters.myconfig;

              }

              else {

              // DEFAUL PATH OF XML

              xmlPath = "config.xml";

              }

              xmlLoader.load(new URLRequest(xmlPath));

              xmlLoader.addEventListener(Event.COMPLETE,xmlLoaded);

              }

              private function xmlLoaded(e:Event):void {

              // XML LOADED COMPLETE

              myXML = new XML(e.target.data);

             

             

              // ADD EVENT LISENER TO FIELDS AND TO (send_btn)

              form_mc.name_txt.addEventListener(TextEvent.TEXT_INPUT,clearAlert);

              form_mc.email_txt.addEventListener(TextEvent.TEXT_INPUT,clearAlert);

              form_mc.message_txt.addEventListener(TextEvent.TEXT_INPUT,clearAlert);

              form_mc.email_txt.addEventListener(Event.CHANGE,checkMail);

              addMouseEvent(form_mc.send_btn,sendEvent);

             

              // CREATE TEXT FORMAT (frm)

              frm = new TextFormat  ;

              frm.leading = 4;

              form_mc.message_txt.defaultTextFormat = frm;

             

             

              // LOAD BACKGROUND IMAGE

              var backLoader:Loader = new Loader();

              backLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,backLoaded);

              backLoader.load(new URLRequest(myXML.img_back));

             

              // ADD KEYBOARD EVENT WHEN PRESSING ENTER KEY

              stage.addEventListener(KeyboardEvent.KEY_DOWN,keyboardDown);

             

              // CREATE THE GREY SPRITE

              greySprite = new Sprite  ;

              greySprite.graphics.beginFill(0x000000,0.2);

              greySprite.graphics.drawRect(0,0,stageWidth,stageHeight);

              greySprite.graphics.endFill();

              greySprite.useHandCursor = false;

             

              // CREATE THE POPUP and ADD EVENTLISTENER TO (close_btn)

              popup_mc = new popup_obj;

              popup_mc.x = (stageWidth - popup_mc.width)/2;

              popup_mc.y = (stageHeight - popup_mc.height)/2;

              addMouseEvent(popup_mc.close_btn,closeEvent);

              }

              private function keyboardDown(e:KeyboardEvent):void{

              if(e.keyCode == 13){

              // STOP USING BREAK LINE IN message_txt

              stage.focus = null;

              }

              }

              private function backLoaded(e:Event):void{

              // BACKGROUND LOADED COMPLETE

              var back_mc:MovieClip = new MovieClip;

              back_mc.addChild(e.target.content);

              addChildAt(back_mc,0);

             

              form_mc.wait_mc.visible = false;

             

              startPageFlip();

             

              // START LOADING GUEST MESSAGE FROM DATABASE

              load_guestbook();

              }

              private function startPageFlip():void{

              var flipedPage:Page = new Page(this, stageWidth, stageHeight, 0, 0);

              flipedPage.turnPageForward();

              }

              private function load_guestbook():void {

              // GET MESSAGES FROM DATABASE USING PHP

              var guestLoad:URLLoader = new URLLoader  ;

              var guestReq:URLRequest = new URLRequest(myXML.phpURL);

              guestReq.method = URLRequestMethod.POST;

              guestReq.data = new URLVariables  ;

              guestReq.data["getMessage"] = 1;

              guestLoad.addEventListener(Event.COMPLETE,bookLoaded);

              guestLoad.load(guestReq);

              }

              private function bookLoaded(e:Event):void {

              // MESSAGES LOADED SUCCESSFULLY FROM DATABASE

              var bookXML:XML = new XML(e.target.data);

              showMessages(bookXML);

              }

              private function showMessages(_xml:XML):void{

              var guest_mc:MovieClip;

              // CREATE (guest_mc) to SHOW EACH GUEST NAME & MESSSAGE

              for (var u=0; u<_xml.guest.length(); u++) {

              guest_mc = new messageObj  ;

              guest_mc.y = 95 * u;

              //CAPITALIZE THE FIRST CHAR IN NAME

              guest_mc._Name = StringUtils.capitalize(_xml.guest[u].name);

              guest_mc._Msg = _xml.guest[u].msg;

              guest_mc._Date = _xml.guest[u].sdate;

              guest_mc.guestName_txt.htmlText = setHtmlFormat(14,myXML.name_color,guest_mc._Name);

              //IF guestMessage_txt TEXT LENGTH > 110 substr guestMessage_txt AND ADD (...)

              guest_mc.guestMessage_txt.htmlText = setHtmlFormat(12,myXML.message_color,StringUtils.capitalize(StringUtils.truncate(_xml.gue st[u].msg,110,"...")));

              guest_mc.guestMessage_txt.setTextFormat(frm);

              guest_mc.tabChildren = false;

              guest_mc.tabEnabled = false;

              // ADD EVENT LISTISTENER  TO (readMore_btn) FOR EACH (guest_mc)

              addMouseEvent(guest_mc.readMore_btn,readEvent);

              msgContainer.addChild(guest_mc);

              }

              // SHOW/HIDE SCROLL

              if (msgContainer.height < mask_mc.height) {

              scroller.scroll_btn.visible = false;

              }

              else {

              this.mouseChildren = false;

              scroller.scroll_btn.y = 0;

              if(msgContainer.y != 10){

              Tweener.addTween(msgContainer,{y:10,time:1.5,onComplete:initScrollPos});

              }

              else{

              initScrollPos();

              }

              scroller.scroll_btn.visible = true;

              // ADD EVENT  TO SCROLL

              addMouseEvent(scroller.scroll_btn,scroll_Event);

              scroller.scroll_btn.addEventListener(MouseEvent.MOUSE_UP,scroll_Event);

              }

              }

              private function initScrollPos():void{

              this.mouseChildren = true;

              dy = 0;

              initPosition = scroller.scroll_btn.y = scroller.bar_mc.y;

              initContentPos = msgContainer.y;

              moveVal = (msgContainer.height-mask_mc.height)/(scroller.bar_mc.height-scroller.scroll_btn.height);

              rectScroll = new Rectangle(scroller.bar_mc.x + 4,scroller.bar_mc.y,0,scroller.bar_mc.height - scroller.scroll_btn.height);

              }

              private function readEvent(me:MouseEvent):void {

              var _this = me.currentTarget;

              switch (me.type) {

              case "mouseOver" :

              _this.alpha = 0.8;

              break;

              case "mouseOut" :

              _this.alpha = 1;

              break;

              case "mouseDown" :

              // SHOW POPUP WITH MORE INFORMATIONS ABOUT THE CURRENT MESSAGE

              popup_mc.pop_nom.htmlText = setHtmlFormat(15,myXML.name_color,_this.parent._Name) + setHtmlFormat(13,myXML.datePosted_color," - Posted "+_this.parent._Date);

              popup_mc.pop_message.htmlText = setHtmlFormat(13,myXML.message_color,StringUtils.capitalize(_this.parent._Msg));

              popup_mc.pop_message.autoSize = TextFieldAutoSize.LEFT;

              popup_mc.pop_message.setTextFormat(frm);

              popup_mc.back_mc.height = popup_mc.pop_message.height + 50;

              popup_mc.x = (stageWidth - popup_mc.width)/2;

              popup_mc.y = (stageHeight - popup_mc.height)/2;

              addChild(greySprite);

              addChild(popup_mc);

              popup_mc.alpha = 0;

              greySprite.alpha = 0;

              Tweener.addTween(popup_mc,{alpha:1,time:0.6});

              Tweener.addTween(greySprite,{alpha:1,time:0.6});

              break;

              }

              }

              private function setHtmlFormat(_size:Number,_color,_txt:String):String{

              var htmlFrm:String  = "<font size='"+_size+"'color='"+_color+"'>"+_txt+"</font>";

              return htmlFrm;

              }

              private function closeEvent(me:MouseEvent):void {

              switch (me.type) {

              case "mouseOver" :

              popup_mc.close_btn.alpha = 0.8;

              break;

              case "mouseOut" :

              popup_mc.close_btn.alpha = 1;

              break;

              case "mouseDown" :

              if (stage.contains(popup_mc)) {

              Tweener.addTween(greySprite,{alpha:0,time:0.6,onComplete:function(){removeChild(greySprit e)}});

              Tweener.addTween(popup_mc,{alpha:0,time:0.6,onComplete:function(){removeChild(popup_mc)}} );

              }

              break;

              }

              }

              private function scroll_Event(me:MouseEvent):void {

              switch (me.type) {

              case "mouseOver" :

              scroller.scroll_btn.alpha = 0.7;

              break;

              case "mouseOut" :

              scroller.scroll_btn.alpha = 1;

              break;

              case "mouseUP" :

              scroller.scroll_btn.stopDrag();

              scroller.scroll_btn.removeEventListener(Event.ENTER_FRAME, scrollMove);

              break;

              case "mouseDown" :

              scroller.scroll_btn.startDrag(false, rectScroll);

              scroller.scroll_btn.addEventListener(Event.ENTER_FRAME, scrollMove);

              stage.addEventListener(MouseEvent.MOUSE_UP, releaseOut);

              break;

              }

              }

              private function scrollMove(event:Event):void {

              dy = Math.abs(initPosition - scroller.scroll_btn.y);

              msgContainer.y = Math.round(dy * -1 * moveVal + initContentPos);

              }

              private function releaseOut(me:MouseEvent):void {

              scroller.scroll_btn.stopDrag();

              scroller.scroll_btn.removeEventListener(Event.ENTER_FRAME, scrollMove);

              stage.removeEventListener(MouseEvent.MOUSE_UP, releaseOut);

              }

              private function sendEvent(e:MouseEvent):void {

              switch (e.type) {

              case "mouseOver" :

              form_mc.send_btn.alpha = 0.7;

              break;

              case "mouseOut" :

              form_mc.send_btn.alpha = 1;

              break;

              case "mouseDown" :

              // CHECK FIELDS AND EMAIL THEN SEND DATA TO PHP

              if (form_mc.name_txt.text == "") {

              stage.focus = form_mc.name_txt;

              show_alert("You must enter the : « Name »");

              }

              else if (form_mc.email_txt.text == "") {

              stage.focus = form_mc.email_txt;

              show_alert("You must enter the : « E-mail »");

              }

              else if (form_mc.validating.currentFrame == 1) {

              stage.focus = form_mc.email_txt;

              form_mc.validating.alpha = 1;

              form_mc.validating.gotoAndStop(1);

              show_alert("« E-mail » address is incorrect");

              }

              else if (form_mc.message_txt.text == "") {

              stage.focus = form_mc.message_txt;

              show_alert("You must enter the : « Message »");

              }

              else {

              sendData();

              }

              break;

              }

              }

              private function checkMail(e:Event):void {

              form_mc.validating.alpha = 1;

              var mail_validation:RegExp = /^[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i;

              mail_validation.test(form_mc.email_txt.text);

              if (mail_validation.test(form_mc.email_txt.text) == true) {

              form_mc.validating.gotoAndStop(2);

              form_mc.alert_txt.text = "";

              }

              else {

              form_mc.validating.gotoAndStop(1);

              }

              }

              private function clearAlert(te:TextEvent):void {

              if (form_mc.alert_txt.text != "") {

              form_mc.alert_txt.text = "";

              }

              }

              private function show_alert(txt:String):void {

              form_mc.alert_txt.htmlText = "<font color='" + myXML.alert_color + "'>" + txt + "</font>";

              }

              private function sendData():void {

              // SEND NAME-EMAIL-MESSAGE TO PHP

              this.mouseChildren = false;

              form_mc.wait_mc.visible = true;

              var phpLoad:URLLoader = new URLLoader  ;

              var phpReq:URLRequest = new URLRequest(myXML.phpURL);

              phpReq.method = URLRequestMethod.POST;

              phpReq.data = new URLVariables  ;

              phpReq.data["name"] = StringUtils.stripTags(form_mc.name_txt.text);

              phpReq.data["email"] = form_mc.email_txt.text;

              phpReq.data["message"] = StringUtils.stripTags(form_mc.message_txt.text);

              phpLoad.addEventListener(Event.COMPLETE,insertPHP);

              phpLoad.load(phpReq);

              }

              private function insertPHP(e:Event):void {

              this.mouseChildren = true;

              var phpXML:XML = new XML(e.target.data);

              form_mc.send_btn.mouseEnabled = true;

              form_mc.wait_mc.visible = false;

              if (phpXML.inserted == 1) {

              startPageFlip();

              form_mc.alert_txt.htmlText = myXML.insert_ok;

              form_mc.validating.alpha = 0;

              form_mc.validating.gotoAndStop(1);

              while (msgContainer.numChildren) {

              msgContainer.removeChildAt(msgContainer.numChildren-1);

              }

              // SHOW THE CURRENT POSTED MESSAGE AND CLEAR FIELDS

              showMessages(phpXML);

              clearFields();

              }

              else {

              form_mc.alert_txt.htmlText = myXML.insert_error;

              }

              }

              private function clearFields():void {

              form_mc.name_txt.text = "";

              form_mc.email_txt.text = "";

              form_mc.message_txt.text = "";

              form_mc.validating.gotoAndStop(1);

              form_mc.validating.alpha = 0;

              }

              private function addMouseEvent(_targ,_func):void {

              _targ.buttonMode = true;

              _targ.mouseChildren = false;

              _targ.addEventListener(MouseEvent.MOUSE_OVER,_func);

              _targ.addEventListener(MouseEvent.MOUSE_OUT,_func);

              _targ.addEventListener(MouseEvent.MOUSE_DOWN,_func);

              }

              }

            }

            • 4. Re: would someone be willing to check as3 code for a guestbook
              Ned Murphy Adobe Community Professional & MVP

              I suggested you show the code that is not working.  What part of the code does not work?  If you say "all of it" then you are likely going to have to hire someone to work this out for you.

              • 5. Re: would someone be willing to check as3 code for a guestbook
                JimmyB29 Level 1

                AHA! I have no idea which part of the code isn't working!:-(

                • 6. Re: would someone be willing to check as3 code for a guestbook
                  Ned Murphy Adobe Community Professional & MVP

                  If you didn't write the code then I would guess that the code is okay but you didn't implement the rest of the design to match the code.  If you didn't implement anything in the file and are just trying to get someone else's design working for you then you should contact whoever that someone else is.

                  • 7. Re: would someone be willing to check as3 code for a guestbook
                    JimmyB29 Level 1

                    Hi, Ned,

                     

                    Would you be willing to look at my code and see what's wrong for a fee? I'm sure the problem is there, but I don't know enough to do it. What would you charge me? I have an idea that it's obvious - but not to me!

                     

                    Thanks,

                     

                    Jimmy

                    • 8. Re: would someone be willing to check as3 code for a guestbook
                      Ned Murphy Adobe Community Professional & MVP

                      Contact me thru my web site (see my profile) - I don't conduct business thru these forums.