Send data from Flash to ASP and back to Flash

Posted on 2009-04-17
Last Modified: 2012-05-06

I need to send data from Flash (I'm a novice in) to ASP and the result back from ASP to Flash.
I found this example (in German language) how to do.
Well it works but only sometimes - almost I see in the browser status bar that data will be send and when the browser shows ready I don't get any result.
So I looked for a better sample but at all I found only samples that send data from Flash to ASP and not back...
Maybe somebody can show my why this sample allmost do not work or has somebody a better sample for?


Question by:andre72
    LVL 15

    Expert Comment

    LVL 15

    Expert Comment

    I translated the site you sent and also found a related article which shows how to set cookies in flash.
    So you can set a cookie from asp and read it in flash.

    Author Comment

    I'm sorry. I made a mistake because of bad description.
    I can't use cookies or parse parameter using html for the embeded object because I need to exchange the parameters at runtime and without change to an othere side.
    Enter your E-Mail address into a flash movie
    Flash givie this E-Mail addresse to send the mail and return the state to flash
    flash shows if anything is right or something goes wrog
    LVL 3

    Accepted Solution

    Unfortunately I am not great with ASP however I have created a PHP version of what you are looking for many times.

    If you are just looking for a contained solution this should do the job for you, if you are completely against PHP I may be able to recode it.

    You can download the source files for this from

    The Flash Code is just the function, you would need to have input textboxes for nameInput, phoneInput, etc. as well as a dynamic field called Output.  Create a button that will run the function sendEmail() and it will pass the information from the input boxes to SendEmail.php

    It will pass the information to the php, the php will process that information and send back if the job was successful or not.  The code is commented and should explain it all.  There is only one thing, you will need to have the directory "inc" and it's files (from the zip link above).  Place the directory in the same one as the files you are running.

    I hope this helps.
    function sendEmail(){
    	//Create the object to hold the variables
    	email = new LoadVars();
    	//enter the variables to be sent to the php form
 = nameInput.text;
 = phoneInput.text;
    	email.postcode = postcodeInput.text;
 = emailInput.text;
    	email.comments = commentsInput.text;
    	email.success = 0;
            //send and receive variables
    	email.sendAndLoad("SendEmail.php", email, "POST" );
    	email.onLoad = function(success){
    		//test to make sure the send and load to php was successful
    		//if it fails at this point it is due to the php having an error
    		//or you are pointing to a file that doesn't exist
    				//Result if Email Sent
    				Output.text = "email sent";
    				//Send the email error from the php script
    				Output.text = this.error;
    			Output.text = "System Error";
    //CODE FOR PHP.  Name file SendEmail.php
    //The inc directory is in the I have linked to.
    //receive the variables from flash
    $name = $_POST["name"];
    $phone = $_POST["phone"];
    $postcode = $_POST["postcode"];
    $email = $_POST["email"];
    $comments = $_POST["comments"];
    //create a variable for the date
    $date = date("r");
    #Make the body text for the email to be sent to Kombat
    $alltext = "
    This is the email we will be sending
    Name:       $name  
    Phone No.:  $phone  
    Post Code:  $postcode  	
    Email:      $email
    ******END OF EMAIL******
    //This will wrap the email so that it is no wider than 55 characthers
    //this is only to make sure the comments won't show up as one line of text
    $allwrap = wordwrap($alltext, 55, "\n", 1);
    //The if statement tests to make sure that the email entered isn't a fake
    //this can be removed but is good to prevent spammers.  It refers to the 
    //function validate Email below.
      if(validateEmail($email) == false){
      	//If check fails, send back that we failed due to an invalid email address
        echo "success=0&error=invalid email";
    	 $mail = new htmlMimeMail();
    	 //set the body of the email to the input from above
    	 //set the email from field
    	 $mail->setFrom("\"Your Name\" <>");
    	 //set the email subject field
    	 $mail->setSubject("Subject for Email To Customer");
    	 //set the email header
    	 $mail->setHeader('X-Mailer', 'Email Form');
    	 //add a date to the header
    	 $mail->setHeader('Date', "$date");
    	//send the email to the email address entered
    		//return 1 to show a successful send
            echo "success=1";
    		//return 0 to show an unsuccessful send with an error message
            echo "success=0&error=email not sent";
    #  Validate the email address
    function validateEmail($email)
       #Make sure the email uses the correct layout eg.
       if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)){
          return false;
       #Retrieve the domain name from the email address.
       list($Username, $Domain) = split("@",$email);
       #Check the MX Record to make sure the domain exists.
       if(getmxrr($Domain, $MXHost)){
          return true;
          if(fsockopen($Domain, 25, $errno, $errstr, 30)){
             return true; 
             return false; 

    Open in new window


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    The goal of the tutorial is to teach the user how to how to record live broadcast.
    The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now