/*ActionScript 3.0 Script created by Adam Khoury @ www.developphp.com*/
// Imports needed for radio button grouping
import fl.controls.RadioButton;
import fl.controls.RadioButtonGroup;
// hide processing CM
processing_mc.visible = false;
// custom function we create to populate the comboBox list
function addCountriesToList ():void {
countryList.addItem( { label: "United States" } );
countryList.addItem( { label: "Mexico" } );
countryList.addItem( { label: "Canada" } );
countryList.addItem( { label: "United Kingdom" } );
}
// Run function above now
addCountriesToList ();
// make radio button group distictions
var radioGroup1:RadioButtonGroup = new RadioButtonGroup("radioGroupGender");
radioMale.group = radioGroup1;
radioFemale.group = radioGroup1;
// build variable name for the URL Variables loader
var variables:URLVariables = new URLVariables;
// Build the varSend variable
var varSend:URLRequest = new URLRequest("form_parse.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
// Build the varLoader variable
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
// handler for the PHP script completion and return of status
function completeHandler(event:Event):void {
// remove processing clip
processing_mc.visible = false;
name_txt.text = "";
email_txt.text = "";
msg_txt.text = "";
kids.value = 0;
checkBox.selected = false;
// Load the response from php here
status_txt.text = event.target.data.return_msg;
}
// Add event listener for submit button click
submit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);
// function ValidateAndSend
function ValidateAndSend (event:MouseEvent):void {
// validate fields
if(!name_txt.length) {
status_txt.text = "Please enter your name";
} else if (!email_txt.length) {
status_txt.text = "Please enter your email";
} else if (!msg_txt.length) {
status_txt.text = "Please enter your message";
} else {
// All is good, send the data now to PHP
processing_mc.visible = true;
// ready the variables in our form for sending
variables.userName = name_txt.text;
variables.userEmail = email_txt.text;
variables.userMsg = msg_txt.text;
variables.userCountry = countryList.value;
variables.userKids = kids.value;
variables.userGender = radioGroup1.selection.value;
variables.userNewsletter = checkBox.selected;
// Send the data to PHP now
varLoader.load(varSend);
} // close else condition for error handling
} // close validate and send function