A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Can someone check this As3 please?

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    4

    Can someone check this As3 please?

    Hi, Ive made this contact form in cs5 as3 from a tutorial. It sends fine but I don't get the sent success or failed message. It says "sending" but the form stays filled in and I don't get the successful message. Here is the as3. I hope someone can help me here!

    Thanks...

    import fl.managers.StyleManager;
    import flash.events.Event;

    email_txt.addEventListener(Event.CHANGE, textChanged);

    function textChanged(evt:Event):void {
    var typed:String = evt.target.text.slice(evt.target.text.length-1, evt.target.text.length);
    if (typed == "\"") {
    evt.target.text = evt.target.text.slice(0, evt.target.text.length-1)+"@";
    }
    }


    StyleManager.setStyle("textFormat", new TextFormat("Verdana", 11, 0x000000));
    const SENDING:String = "Sending";
    const SENT_SUCCESS:String = "Successful";
    const SENT_FAILED:String = "Unsuccessful";
    var tmr:Timer;



    function resetTextFields():void {
    name_txt.text = "";
    email_txt.text = "";
    message_txt.text = "";
    }

    function resetContactForm():void {
    submit_btn.enabled = true;
    feedback_mc.visible = false;
    clearErrors();
    }

    function afterTmrWait(evt:TimerEvent):void {
    tmr.stop();
    tmr.removeEventListener(TimerEvent.TIMER, afterTmrWait);
    resetContactForm();
    }

    // From AS3 Doc.
    function validateEmail(str:String):Boolean {
    var pattern:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;
    var result:Object = pattern.exec(str);
    if(result == null) {
    return false;
    }
    return true;
    }

    function submitForm(evt:MouseEvent):void {

    clearErrors();

    var passChecks:Boolean = true;

    if(name_txt.text.length < 1) {
    nameError_mc.visible = true;
    passChecks = false;
    }
    if(!validateEmail(email_txt.text)) {
    emailError_mc.visible = true;
    passChecks = false;
    }
    if(message_txt.text.length < 1) {
    messageError_mc.visible = true;
    passChecks = false;
    }

    if(passChecks) {
    submit_btn.enabled = false;
    feedback_mc.visible = true;
    feedback_mc.gotoAndStop(SENDING);

    var urlVars:URLVariables = new URLVariables();
    var urlReq:URLRequest = new URLRequest("send_email.php");
    var ldr:URLLoader = new URLLoader();

    urlVars.name = name_txt.text;
    urlVars.email = email_txt.text;
    urlVars.message = message_txt.text;
    urlReq.data = urlVars;
    urlReq.method = URLRequestMethod.POST;
    ldr.addEventListener(Event.COMPLETE, serverFeedback);
    ldr.load(urlReq);
    }
    }

    function serverFeedback(evt:Event):void {
    var ldr:URLLoader = evt.target as URLLoader;
    var urlVars:URLVariables = new URLVariables(ldr.data);

    if(urlVars.result == SENT_SUCCESS) {
    feedback_mc.gotoAndStop(SENT_SUCCESS);
    resetTextFields();
    } else if(urlVars.result == SENT_FAILED) {
    feedback_mc.gotoAndStop(SENT_FAILED);
    }

    tmr = new Timer(3000, 1);
    tmr.addEventListener(TimerEvent.TIMER, afterTmrWait);
    tmr.start();
    }

    function clearErrors():void {
    nameError_mc.visible = false;
    emailError_mc.visible = false;
    messageError_mc.visible = false;
    }



    submit_btn.addEventListener(MouseEvent.CLICK, submitForm);

    resetTextFields();
    resetContactForm();

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Are you using a server to test the movie? Another problem could be the php file.
    - The right of the People to create Flash movies shall not be infringed. -

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center