...

View Full Version : as3 contact form: null object reference



jpolo9
05-06-2009, 06:45 PM
I am getting the error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MySite_fla::contactForm_8/sendForm()

Any idea what the null object reference is is the sendForm() method?


Thanks,
-Jesse


//---------------Setup variables
var loader:URLLoader = new URLLoader();
var req:URLRequest = new URLRequest("contact.php");
var variables:URLVariables = new URLVariables();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
req.method = URLRequestMethod.POST;
//--------------Set tab index
first_name_txt.tabIndex = 0;
last_name_txt.tabIndex = 1;
address_txt.tabIndex = 2;
city_txt.tabIndex = 3;
state_txt.tabIndex = 4;
zip_txt.tabIndex = 5;
phone_txt.tabIndex = 6;
email_txt.tabIndex = 7;
message_txt.tabIndex = 8;
send_button.tabIndex = 9;
reset_button.tabIndex = 10;
//--------------Set listener fot textfield changes
first_name_txt.addEventListener(Event.CHANGE, txErrorCheck);
last_name_txt.addEventListener(Event.CHANGE, txErrorCheck);
address_txt.addEventListener(Event.CHANGE, txErrorCheck);
city_txt.addEventListener(Event.CHANGE, txErrorCheck);
state_txt.addEventListener(Event.CHANGE, txErrorCheck);
zip_txt.addEventListener(Event.CHANGE, txErrorCheck);
phone_txt.addEventListener(Event.CHANGE, txErrorCheck);
email_txt.addEventListener(Event.CHANGE, txErrorCheck);
message_txt.addEventListener(Event.CHANGE, txErrorCheck);
function txErrorCheck(event:Event):void {
if (txError.text.length>0) {
txError.text = "";
}
}
//--------------Set up form buttons
send_button.addEventListener(MouseEvent.CLICK, sendForm);
reset_button.addEventListener(MouseEvent.CLICK, resetForm);
//--------------Validate fields and submit form
function sendForm(evt:MouseEvent):void {
if (first_name_txt.text.length<=0) {
txError.text = "** First Name Required **";
} else if (!email_txt.text.length || email_txt.text.indexOf("@") == -1 || email_txt.text.indexOf(".") == -1) {
txError.text = "missing field/Invalid email";
} else if (message_txt.text==""||message_txt.text.length<=1) {
txError.text = "** Message Required **";
} else {
this.gotoAndPlay("wait");
variables.senderFirstName = first_name_txt.text;
variables.senderLastName = last_name_txt.text;
variables.senderAddress = address_txt.text;
variables.senderCity = city_txt.text;
variables.senderState = state_txt.text;
variables.senderZip = zip_txt.text;
variables.senderPhone = phone_txt.text;
variables.senderEmail = email_txt.text;
variables.senderMsg = message_txt.text;
req.data = variables;
loader.load(req);
loader.addEventListener(Event.COMPLETE, receiveLoad);
}
}
function receiveLoad(evt:Event):void {
if (evt.target.data.retval == 1) {
this.gotoAndStop("output");
} else {
this.gotoAndStop("error");
}
}
//--------------Reset form
function resetForm(evt:MouseEvent):void {
first_name_txt.text="";
last_name_txt.text="";
address_txt.text="";
city_txt.text="";
state_txt.text="";
zip_txt.text="";
phone_txt.text="";
email_txt.text="";
message_txt.text="";
}
stop();



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum