A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: passing data in multiple page survery

  1. #1
    Member
    Join Date
    Aug 2008
    Posts
    75

    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");
    		
    	
    	}

  2. #2
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    When a user goes to the "next page", are you pushing the form data into your variables object? The fields will no longer be accessible from your submission page, so they need to be saved before navigating away.
    Search first, asked questions later.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center