Skip to main content
Known Participant
January 16, 2013
Question

contact form functionality

  • January 16, 2013
  • 1 reply
  • 1494 views

Hello there,

Ok so here's my problem. I have almost completed my website with all the buttons and MC's communicating nicely with their respective frames. I am on my final frame being the "Contact Form" frame. I searched the web to find a tutorial in finding as3 contact form.

Link: http://www.republicofcode.com/tutorials/flash/as3contactform

It was easy to follow and helpful. I created a php file called "mail.php" and an .fla file called "contactmovie.fla".

I followed the steps and finally put in the required as3 in the contactmovie.fla. I tested contactmovie.fla in a browser effectively creating an swf file in the same name. In the browser, I typed into the text fields and pressed submit which returned a "Message Sent" response. All appears well.

BUT...

When I want to incorporate this into a website that I am creating in flash under a different file name I have issues.

1. I am not sure whether I need to import the contactmovie.swf file into the website .fla file which I called allrounda.fla (also, when I do this no text appears); or,

2. I can simply copy the frames in the contactmovie.fla file and paste the frames into the allrounda.fla file.

Eitherway, doesn't seem to work. In point 2,  the text is displayed but when I type the details in the text field, no "Message Sent" is displayed.

This indicates to me that the script is not communicating with the text fields which has the instance names of name_txt, email_txt and message_txt. The instance names do correspond to the script. The contact form created is not on frame 1 but frame 5. There is an MC that behaves like a button that takes you to frame 5 where the contact form is on.

It is probably a small issue with an as3 guru.

AS3 SCRIPT

//CONTACT FORM //

submit_btn.addEventListener(MouseEvent.CLICK, sendMessage);

function sendMessage(e:MouseEvent):void{

var my_vars:URLVariables = new URLVariables();

my_vars.senderName = name_txt.text;

my_vars.senderEmail = email_txt.text;

my_vars.senderMsg = message_txt.text;

var my_url:URLRequest = new URLRequest("allrounda.php");

my_url.method = URLRequestMethod.POST;

my_url.data = my_vars;

var my_loader:URLLoader = new URLLoader();

my_loader.dataFormat = URLLoaderDataFormat.VARIABLES;

my_loader.load(my_url);

name_txt.text = "";

email_txt.text = "";

message_txt.text = "Message Sent";

}

PHP SCRIPT

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Untitled Document</title>

</head>

<body>

<?php

$to = "dalipagic@gmail.com";

$subject = ($_POST['senderName']);

$message = ($_POST['senderMsg']);

$message .= "\n\n---------------------------\n";

$message .= "E-mail Sent From: " . $_POST['senderName'] . " <" . $_POST['senderEmail'] . ">\n";

$headers = "From: " . $_POST['senderName'] . " <" . $_POST['senderEmail'] . ">\n";

if(@mail($to, $subject, $message, $headers))

{

echo "answer=ok";

}

else

{

echo "answer=error";

}

?>

</body>

</html>

/////////////////////////////////////

Or is it the case that this will all work when I have uploaded both .fla and .php file to the server?

I know it is a lot to ask but it would be appreciated.

Kind regards,

Dean D

This topic has been closed for replies.

1 reply

dali1deaAuthor
Known Participant
January 16, 2013

This is my whole script. I know it is not the cleanest way to do it but it works.

stop();

pic4_mc.buttonMode = true;

pic4_mc.useHandCursor = true;

pic14_mc.buttonMode = true;

pic14_mc.useHandCursor = true;

pic1_mc.buttonMode = true;

pic1_mc.useHandCursor = true;

home_btn.buttonMode = true;

home_btn.useHandCursor = true;

quote_btn.buttonMode = true;

quote_btn.useHandCursor = true;

gallery_btn.buttonMode = true;

gallery_btn.useHandCursor = true;

contact_btn.buttonMode = true;

contact_btn.useHandCursor = true;

//Cleaning services pic

pic4_mc.addEventListener(MouseEvent.ROLL_OUT, fl_MouseOutHandler_5);

function fl_MouseOutHandler_5(event:MouseEvent):void

{

    pic4_mc.alpha = 0.5;

    trace("Moused out");

}

pic4_mc.addEventListener(MouseEvent.ROLL_OVER, fl_MouseOverHandler_5);

function fl_MouseOverHandler_5(event:MouseEvent):void

{

    pic4_mc.alpha = 1.0;

    trace("Moused over");

}

//Garden maintenance pic

pic14_mc.addEventListener(MouseEvent.ROLL_OUT, fl_MouseOutHandler_6);

function fl_MouseOutHandler_6(event:MouseEvent):void

{

    pic14_mc.alpha = 0.5;

    trace("Moused out");

}

pic14_mc.addEventListener(MouseEvent.ROLL_OVER, fl_MouseOverHandler_6);

function fl_MouseOverHandler_6(event:MouseEvent):void

{

    pic14_mc.alpha = 1.0;

    trace("Moused over");

}

//Handyman picture

pic1_mc.addEventListener(MouseEvent.ROLL_OUT, fl_MouseOutHandler_7);

function fl_MouseOutHandler_7(event:MouseEvent):void

{

    pic1_mc.alpha = 0.5;

    trace("Moused out");

}

pic1_mc.addEventListener(MouseEvent.ROLL_OVER, fl_MouseOverHandler_7);

function fl_MouseOverHandler_7(event:MouseEvent):void

{

    pic1_mc.alpha = 1.0;

    trace("Moused over");

}

//home btn function

home_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_9);

function fl_ClickToGoToAndStopAtFrame_9(event:MouseEvent):void

{

    gotoAndStop(1);

}

// Cleaning Services btn function

pic4_mc.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_6);

function fl_ClickToGoToAndStopAtFrame_6(event:MouseEvent):void

{

    gotoAndStop(2);

}

//Garden Maintenance btn function

pic14_mc.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_7);

function fl_ClickToGoToAndStopAtFrame_7(event:MouseEvent):void

{

    gotoAndStop(3);

}

//Handyman btn function

pic1_mc.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_8);

function fl_ClickToGoToAndStopAtFrame_8(event:MouseEvent):void

{

    gotoAndStop(4);

}

/* Click to Go to Frame and Stop

Clicking on the specified symbol instance moves the playhead to the specified frame in the timeline and stops the movie.

Can be used on the main timeline or on movie clip timelines.

Instructions:

1. Replace the number 5 in the code below with the frame number you would like the playhead to move to when the symbol instance is clicked.

*/

quote_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_10);

function fl_ClickToGoToAndStopAtFrame_10(event:MouseEvent):void

{

    gotoAndStop(5);

}

/* Click to Go to Frame and Stop

Clicking on the specified symbol instance moves the playhead to the specified frame in the timeline and stops the movie.

Can be used on the main timeline or on movie clip timelines.

Instructions:

1. Replace the number 5 in the code below with the frame number you would like the playhead to move to when the symbol instance is clicked.

*/

gallery_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_11);

function fl_ClickToGoToAndStopAtFrame_11(event:MouseEvent):void

{

    gotoAndStop(6);

}

/* Click to Go to Frame and Stop

Clicking on the specified symbol instance moves the playhead to the specified frame in the timeline and stops the movie.

Can be used on the main timeline or on movie clip timelines.

Instructions:

1. Replace the number 5 in the code below with the frame number you would like the playhead to move to when the symbol instance is clicked.

*/

contact_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_12);

function fl_ClickToGoToAndStopAtFrame_12(event:MouseEvent):void

{

    gotoAndStop(7);

}

//CONTACT FORM //

submit_btn.addEventListener(MouseEvent.CLICK, sendMessage);

function sendMessage(e:MouseEvent):void{

var my_vars:URLVariables = new URLVariables();

my_vars.senderName = name_txt.text;

my_vars.senderEmail = email_txt.text;

my_vars.senderMsg = message_txt.text;

var my_url:URLRequest = new URLRequest("allrounda.php");

my_url.method = URLRequestMethod.POST;

my_url.data = my_vars;

var my_loader:URLLoader = new URLLoader();

my_loader.dataFormat = URLLoaderDataFormat.VARIABLES;

my_loader.load(my_url);

name_txt.text = "";

email_txt.text = "";

message_txt.text = "Message Sent";

}

Inspiring
January 16, 2013

Or is it the case that this will all work when I have uploaded both .fla and .php file to the server?

.fla = Source-Datei -> You never upload one of these to a server

.swf= compiled Source ->This would be the version you upload

.html= the wrapper of the .swf -> This also must sit on the server

.php=This also must sit on the server.

Testing this application only locally is pointless: since the php file does not work if its not running in a server environment (you could set up a virtual local server, but that depends on your expertise), that has php enabled.

The Moment the php is uploaded to your Hoster if he`s any good, he won`t allow to call that php from another domain (such as your local computer), so you have to get swf/html/php in the same directory and test it from there.

dali1deaAuthor
Known Participant
January 16, 2013

Hello Mocca!

I thought so. So basically what I have done thus far is unknown until I but up the .swf, .fla, .php and html file ont the same root folder of the server.

Ok, so the real problem I have is a conflict with the moviecontact.swf file inside my website.swf file. The website goes bizerk. It seems like the stop (); function is overriden by the contactmovie.swf. Is there an event listener and loading function that needs to be included in the website.fla script for it to accept the contactmovie.swf file?

By the way thanks for yesterdays help. I use to play around the old as2 MX2004 version many moons ago and trying to get up to speed with as3 which I actually prefer in a wierd way. Change of employment has brought me back to my calling/destiny...FLASH!

Regards,

Dean D