Passing Values from Storyline to PHP via FLASH

Special thanks to Prakash, for creating the flash file. In this post we shall learn, how to use Storyline to get data from user (for example: Name and Email ID); and then store it in a text file (.txt) on the server.

For this, we shall be using:

  • Storyline: which will keep a Flash form to collect data
  • A FLASH form inside the .story file: which shall collect the data and give it to PHP file
  • PHP [no prior experience required]: This will update the collected data on the server, in form of a .txt file

Here is the workflow for the same:


Steps:

Step 1: Create the FLASH form in Adobe Flash or equivalent program. Let us assume, we are capturing two variables – name and email id, both of which are mandatory. On clicking the submit button, it must trigger the following code:

———————————————————————————————–

if (f1 == 1 && f2 == 1) /*Check if both name and email id are filled*/

{

var my_vars:URLVariables = new URLVariables();

my_vars.senderName = name_txt.text;

my_vars.senderEmail = mail_txt.text;


var my_url:URLRequest = new URLRequest(“process_data.php”); /*this line calls the php file ‘process_data.php’*/

my_url.method = URLRequestMethod.POST;

my_url.data = my_vars;


var my_loader:URLLoader = new URLLoader();

my_loader.dataFormat = URLLoaderDataFormat.VARIABLES;

my_loader.load(my_url);


name_txt.text = “name”;

mail_txt.text = “E-mail”;

f1 = 0;

f2 = 0;


score=1;

ExternalInterface.call(‘GetPlayer().SetVar’,’gameScore’,score);

/*Trigger the variable “score” which can be used by storyline to check if the data is submitted*/

trace(score);

}

else

{

trace(“Not sent”);

}

———————————————————————————————–

Step 2: Open a .story file, and insert the FLASH .swf on the first screen.

———————————————————————————————–

Step 3: Open a notepad and write the following code:

<?php

$message = “n” . “Name: “.$_POST[‘senderName’]. ” “.”E-mail : “.$_POST[‘senderEmail’] . “n”;

$File = “data.txt”;

$Handle = fopen($File, ‘a+’);

fwrite($Handle, $message);

print “Data Written”;

fclose($Handle);

?>

Save the file as “process_data.php“.

———————————————————————————————–

Now publish the .story file.

Step 4: Paste process_data.php in the folder where story.html is kept.

Step 5: Create a data.txt file and paste it in the folder where story.html is present.



And it is done! Now whenever a person fills the form and submits it. A new record is added to data.txt.

PS: What if, I want to mail the data to an email ID instead of storing it?

In the Step 3 – process_data.php, write the following code:

 


 

<?php

$to = “youremail@id.com”; /*put the recipient email id here*/

$subject = ($_POST[‘senderSub’]);

$message = ($_POST[‘senderMsg’]);

$message .= “nn—————————n”;

$message .= “E-mail Sent From: ” . $_POST[‘senderName’] . ” <” . $_POST[‘senderEmail’] . ” <“. $_POST[‘senderSub’]. “>n”;

$headers = “From: ” . $_POST[‘senderName’] . ” <” . $_POST[‘senderEmail’] . “>n”;

if(@mail($to, $subject, $message, $headers))

{

echo “answer=ok”;

}

else

{

echo “answer=error”;

}

?>

Rest all the steps are same.

Leave a Comment

Your email address will not be published. Required fields are marked *

Top