passing data in multiple page survery
I have a four page survery. I am using labels for the pages so they are all on the same timeline. When the user gets to the last page there is a submit button that sends all the variables to a php mailform file. However I keep getting TypeError: Error #1009: Cannot access a property or method of a null object reference. I dont think my variables are not being passed. What can I do?
Here is my code:
Code:
var variables:URLVariables = new URLVariables();
var varSend:URLRequest = new URLRequest("mailform.php");
var varLoader:URLLoader = new URLLoader;
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
stop();
//sets focus to the Name text box
stage.focus = name_txt;
//handle events for buttons
form2.addEventListener(MouseEvent.CLICK,clickHandler);
function clickHandler(evtObj:MouseEvent){
//validate form fields
if(!name_txt.length) {
results_txt.text = "Please enter your name.";
} else if(!email_txt.length) {
results_txt.text = "Please enter an email address";
}else if(!validateEmail(email_txt.text)) {
results_txt.text = "Please enter a VALID email address";
} else if(message_txt.length <= 1) {
results_txt.text = "Please enter a message.";
} else {
trace("The " + evtObj.target.name + " button was clicked");
gotoAndStop(evtObj.target.name)
}
}
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 called from method, contains validation logic and var data to be sent to form
function sendData(event:MouseEvent):void{
variables.textName = name_txt.text;
variables.textEmail = email_txt.text;
variables.textMessage = message_txt.text;
variables.textCompany = company_txt.text;
varLoader.load(varSend);
trace("Email: "+email_txt.text);
trace("Text length: "+message_txt.length);
trace("Valid email: "+validateEmail(email_txt.text));
trace("Message: "+message_txt.text);
trace("Form validated");
}