Complete Flash / AS Noob here. Friend wanted a change in Email address and I’m assisting. I notice at the bottom it posts to a formmail.php file but I was wondering if there was an easier way or perhaps someone could help me understand what exactly it POSTS and how AS handles POST methods so I can rewrite a script. As formmail.php is some script from “Andrew Riley (webmaster@boaddrink.com)”
function playTier() {
switch(this.tierContent.tier_txt.text) {
case "Sinking Ship":
bullseye_mc.arrow_ani._x = 205; break;
case "Piggy Bank":
bullseye_mc.arrow_ani._x = 180; break;
case "Loose Change":
bullseye_mc.arrow_ani._x = 155; break;
default:
trace("error for arrow posX")
}
bullseye_mc.arrow_ani.play();
sendEmail();
}
tierContent._alpha = 100;
var recipient = "user@website.com";
var subject = "AP Form";
var nameField:String;
var emailField:String;
var phoneField:String;
var commentsField:String;
//alert format
var alertFormat = new TextFormat();
alertFormat.color = 0xFF0000;
var fields:Array = new Array("name_txt", "email_txt", "phone_txt", "comments_txt");
function alertField():Boolean {
var checkFailure:Number = 0;
for (i=0; i<fields.length; i++) {
if (this[fields[i]].length<1) {
checkFailure++;
trace(checkFailure+"-checkFailure");
this[fields[i]].text = "Required!";
this[fields[i]].setTextFormat(alertFormat);
}
}
if (checkFailure>0) {
return false;
} else {
return true;
}
}
function successWindow() {
this.createTextField("my_txt",1,90,212,300,0);
this.my_txt.background = true;
this.my_txt.backgroundColor = 0x00CC00;
my_txt.multiline = true;
my_txt.autoSize = true;
my_txt.wordWrap = true;
var my_fmt:TextFormat = new TextFormat();
my_fmt.color = 0xFFFFFF;
my_fmt.size = 11;
my_fmt.font = "Verdana";
my_txt.text = "Thank You. Your information has been submitted.";
my_txt.setTextFormat(my_fmt);
}
function progressWindow() {
this.createTextField("progress_txt",1,90,212,300,0);
this.progress_txt.background = true;
this.progress_txt.backgroundColor = 0xFD530B;
progress_txt.multiline = true;
progress_txt.autoSize = true;
progress_txt.wordWrap = true;
var progress_fmt:TextFormat = new TextFormat();
progress_fmt.color = 0xFFFFFF;
progress_fmt.size = 11;
progress_fmt.font = "Verdana";
progress_txt.text = "Transmitting your information.";
progress_txt.setTextFormat(progress_fmt);
}
function sendEmail() {
switch (alertField()) {
case true :
progressWindow()
trace("break!");
var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function(success:Boolean) {
if (success) {
trace("Form sent!");
successWindow();
} else {
trace("Error in sending");
}
};
var send_lv:LoadVars = new LoadVars();
send_lv.recipient = "user@website.com";
send_lv.subject = "AP Form";
send_lv.sort = "order:name,company,email,phone,question1,question2,question3,question4,question5,question6,question7,question8"
send_lv.name = this._parent.q9.name_txt.text;
send_lv.company = this._parent.q9.company_txt.text;
send_lv.email = this._parent.q9.email_txt.text;
send_lv.phone = this._parent.q9.phone_txt.text;
send_lv.question1 = this._parent._parent.qArray[0];
send_lv.question2 = this._parent._parent.qArray[1];
send_lv.question3 = this._parent._parent.qArray[2];
send_lv.question4 = this._parent._parent.qArray[3];
send_lv.question5 = this._parent._parent.qArray[4];
send_lv.question6 = this._parent._parent.qArray[5];
send_lv.question7 = this._parent._parent.qArray[6];
send_lv.question8 = this._parent._parent.qArray[7];
send_lv.sendAndLoad("formmail.php",result_lv,"POST");
if(lvBytesLoaded < lvBytesTotal) {
progressWindow()
}
break;
case false :
trace("Error missing fields- nothing sent");
break;
default :
trace("Something bad happen");
break;
}
};
If you could post the exact change that your friend wants to make, it would be helpful in answering your question. It sounds like you just need to change the email address, though.
A short answer to your question:
There is some confusion built into this code – there are variables defined and populated that you would expect to be what is sent to the server. BUT, these variables are not referred to later on, when the information is being packaged up in the
send_lvobject to be sent up to the server.If you need to change the email address that the email is going to, change
send_lv.recipient = "user@website.com";tosend_lv.recipient = "newEmail@domain.com", or whatever.You could modify to code to make use of the
recipientvar that is defined near the top of the code, like so:send_lv.recipient = recipient;If you do this, then you need to change
var recipient = "user@website.com";tovar recipient = "newEmail@domain.com";.A longer answer to your question:
It’s been a pretty long time since I’ve worked with AS2, but what the code you posted is doing, in general, is gathering the elements of an email and then sending those elements to a PHP script. The PHP script will use the elements it receives to construct and then send an email. In this case, the email will go to
user@website.com, with a subject line ofAP Form. My guess is that the remaining elements –name,company,email,phone, and the list of questions (or question answers, more likely) will be used to construct the body of the email.The
send_lvobject represents the information that will be sent to the server. It is also the means of sending the information to the server (send_lv.sendAndLoad()). ThesendAndLoadmethod sends information to the server and requests a response, which in this case triggers thesuccessWindowfunction. In between the time that the information is sent and the time a result is received from the server, a progress window is displayed.You can read up a bit on this method on the LiveDocs documentation. It’s pretty informative, and explains the difference between the
sendAndLoad,send, andloadmethods.Hope that helps.