Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 636
  • Last Modified:

Send data from Flash to ASP and back to Flash

Hi,

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 http://www.aspheute.com/artikel/20000719.htm (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?

Thanks,

Andre
0
andre72
Asked:
andre72
  • 2
1 Solution
 
spprivateCommented:
0
 
spprivateCommented:
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.

http://translate.google.com/translate?hl=en&sl=de&u=http://www.aspheute.com/artikel/20000719.htm&ei=7qXoSZqhD42Ntgeei_3OBQ&sa=X&oi=translate&resnum=1&ct=result&prev=/search%3Fq%3Dhttp://www.aspheute.com/artikel/20000719.htm%26hl%3Den%26sa%3DG
0
 
andre72Author Commented:
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.
Example:
Enter your E-Mail address into a flash movie
Flash givie this E-Mail addresse to asp.net
asp.net send the mail and return the state to flash
flash shows if anything is right or something goes wrog
0
 
CraybeCommented:
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 http://www.craybe.com.au/Email.zip

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.
//CODE FOR FLASH
function sendEmail(){
	//Create the object to hold the variables
	email = new LoadVars();
	//enter the variables to be sent to the php form
	email.name = nameInput.text;
	email.phone = phoneInput.text;
	email.postcode = postcodeInput.text;
	email.email = 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
		if(success){
			if(email.success){
				//Result if Email Sent
				Output.text = "email sent";
			}else{
				//Send the email error from the php script
				Output.text = this.error;
			}
		}else{
			Output.text = "System Error";
		}
	}
}
 
 
//CODE FOR PHP.  Name file SendEmail.php
<?php
session_start();
//The inc directory is in the Email.zip I have linked to.
include("inc/htmlMimeMail.php");
//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 = "
<PRE> 
This is the email we will be sending
 
Name:       $name  
Phone No.:  $phone  
Post Code:  $postcode  	
Email:      $email
 
Message:
$comments
******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";
  }else{
	 $mail = new htmlMimeMail();
	 //set the body of the email to the input from above
	 $mail->setHTML($allwrap);
	 //set the email from field
	 $mail->setFrom("\"Your Name\" <youremail@email.com>");
	 //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
    if($mail->send(array("<$email>"))){ 
		//return 1 to show a successful send
        echo "success=1";
    }else{
		//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. test@domain.com.au
   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;
   }
   else 
   {
      if(fsockopen($Domain, 25, $errno, $errstr, 30)){
         return true; 
      }else{
         return false; 
      }
   }
}
 
?>

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now