PDA

View Full Version : Sending Variables to PHP from Flash And Back again!


Jubba
03-16-2003, 09:42 PM
This is part 1 of a 3 part tutorial. The parts are:

Part 1: A simple setup that will send variables from a Flash movie to a PHP script and then that PHP script will print the variables out.

Part 2: Sending variables from a Flash Movie to a PHP script, and then using that PHP script to send an e-mail.

Part 3: Sending variables from Flash to a PHP script. Saving those variables to a text file, then calling them back into Flash to form a guestbook/shoutbox/tagboard within Flash.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Flash Player set-up
First you need to set up the input boxes. Create an Input box by using the "Text tool" In the text properties box, you must give the input box a name. It doesn't matter what the name is, but you must remember that name because we are going to be using it in the PHP script in a few minutes.

In my file I made three input boxes. I named them "name", "age", and "eye". Simple enough right? Ok, now we have to make the button to open up the PHP page. To open up a new page from Flash we use getURL(). The code that I used looks like this:
submit.onPress = function () {
getURL ("getVars.php", "_blank", "POST");
}
getVars.php is the name of the PHP file that is our target.
_blank makes the button open up a new page.
POST is the method in which to transfer the variables. The other option is GET.

Thats it for the Flash part. :battery:

PHP Page set-up
The PHP code is simple:
<?

// Recieving the variables.
$name = $_POST['name'];
$age = $_POST['age'];
$eye = $_POST['eye'];

// printing out the variables
print "Your name is ". $name . ".<br>";
print "You are ". $age ." years old.<br>";
print "You have ". $eye ." eyes.<br>";

?>


Now a quick explanation of the code:

The first three lines recieve the variables from the scripting using $_POST[]; This is necessary because the more recent versions of PHP have global variables turned off by default. On some hosts, your script will not work without using this method. You can name the variable whatever you like on the left of the equal sign ("="), but on the right, you must put the variable of your input text box.

The second 3 lines print out the strings. The extra periods (".") in there are used to connect the strings together. Its called the concatenation operator. For more about that go here: Click Here! (http://www.lyris.com/mshelp/Stringconcatenation.html)

Sorry, I had to take out the script in action link because the server that the script was set up on was taken down.

I am going to be re-writing this as a real tutorial to be posted on Kirupa's main tutorial page. But I wrote this up while it was fresh in my mind. Hope it helps.

Cheers,
Jubs :crazy:

Jubba
03-17-2003, 03:05 PM
This is part 2 of a 3 part tutorial. The parts are:

Part 1: A simple setup that will send variables from a Flash movie to a PHP script and then that PHP script will print the variables out.

Part 2: Sending variables from a Flash Movie to a PHP script, and then using that PHP script to send an e-mail.

Part 3: Sending variables from Flash to a PHP script. Saving those variables to a text file, then calling them back into Flash to form a guestbook/shoutbox/tagboard within Flash.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Ok, this is basically a combination of the post above, and this thread that I created the other night about using the mail() function: Click Here! (http://www.kirupaforum.com/forums/showthread.php?s=&threadid=17313)

Since most of this is already explained in those two posts, this section of the tutorial is going to be small because it serves only as a link between those two. Here we go!

Flash Set-up

The only difference between this file and the file before is the script for the button. You set everything up the same way. Create the input text boxes and give them a suitable name. I gave my three input boxes the names "name", "email", and "message".

The code on the button changes a little because now, we don't want to open another page. We just want the e-mail to be sent when the user clicks the Flash button. So, we won't be using getURL() but instead we will use loadVariablesNum(). The code looks like this:

sendButton.onPress = function(){
loadVariablesNum("mailTut.php", 0, "POST");
}

this takes the variables from level "0" and sends them to the script contained in "mailTut.php" using the "POST" method.

PHP Set-up

Now, if you read thru those other two posts that I showed you, then you should have no problem understanding the rest of this post. If you didn't read thru them, then you still won't have a problem because its very simple. Here is the code:

<?

// Recieving and Creating Variables...
$Name = $_POST['name'];
$Email = $_POST['email'];
$Message = $_POST['message'];
$Subject = "Test E-mail Tutorial";
$Header = "From: $Name <$Email>";


//Performing Mail script...
mail($Email, $Subject, $Message, $Header);

?>

The first 5 lines of code are "Recieving and Creating Variables". This recieves the variables from the Flash movie and then creates the Subject and Header variables to be used in the mail() script.

The mail() script is then executed. I already explained all of this stuff in the other tutorial that can be found here: Click Here (http://www.kirupaforum.com/forums/showthread.php?s=&threadid=17313)

Ok thats its for this one.

Sorry, I had to take out the script in action link because the server that the script was set up on was taken down.
Cheers,
Jubs :geek:

Jubba
03-17-2003, 03:11 PM
File Attachments

File #1: Sending Variables to PHP from Flash

Jubba
03-17-2003, 03:12 PM
File Attachments

File #2: Using Flash and PHP to send an e-mail.

Jubba
03-18-2003, 08:13 PM
Ok, re-reading my second post, I don't think I was 100% clear with what I was trying to do. My files were set up so that you could input YOUR e-mail address so you could send yourself an e-mail. And this would show you that the script worked and you could see it work. If you were to change this script around so that it would send to you from your server you would change this line:


// change it from this:
$Email = $_POST['email'];

// to this:
$Email = "myname@mydomain.com";


The point of the tutorial was to give you the basics and then you could edit the script from there. Once this is posted into a larger, more formal tutorial for Kirupa's site, then it will (hopefully) be much easier to understand...

OKtrust
06-07-2003, 05:58 PM
well done !

brooklyniteOne
06-10-2003, 03:15 PM
outstanding!

Jubba
06-21-2003, 04:07 PM
Ok here's part 3, but its not the original part 3. :) I'm going to make this slightly longer than originally planned, but hopefully it will be more in-depth.

This part will show you how to send a variable to PHP, and bring it back into Flash.

The source files are attached at the bottom of the post for those that need them. :)


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Flash Player set-up

The Flash set up is quite simple. You need an input text-box and a dynamic text box. Give the input box a variable name of "name" (without the quotes) and the dynamic box a variable name of "read" (without the quotes).

Create a button. I used my normal naming system and I called it "mc_button_submit_vars" You may call it whatever you wish.

Now that the file is set up we need to add the code. Its not too terribly difficult.


mc_button_submit_vars.onPress = function ()
{
loadVariablesNum ("kirupa_tutorial.php", 0, "POST");
};


As you can see we are using the same method as in the previous posts to load the variables.

Ok, our Flash file is set up, now we want to set up the PHP page...

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

PHP File set-up

Again, this is quite simple. :)

Here is the code:


<?
$name = $_POST['name'];

print "read=Your name is " . $name . ".";
?>


All this does is catch the variable, and then prints it out in a format that Flash can read. :)

Here is a link to a working example: http://www.bluefinatlantic.com/egTest/send_receive_php.htm

Scootman
07-27-2003, 09:32 PM
wow jubba that was great.... is there any chance you could do a tutorial on a message board (doesnt seem a whole lot different from this, but i know it needs a mySQL database right?)...

phorte
08-08-2003, 03:06 AM
thats great man!! :A+: :)

but one more thing.. how would you do it so that you could create the vaiables like "post1_name" and that would be the name of the first poster in a guestbook etc.. if u get what i mean??


and one more thing.. on the last part.. how would u then save those variables to a text file and then how would u recall them from there??


-Scotty

OKtrust
08-08-2003, 01:28 PM
hi Jubba,
at Part 1, because I want to hide AS from viewing, I put the AS into movie, then movie, then movie (instead of first frame at root )


_root.submit.onPress = function () {
getURL ("getVars.php", "_blank", "POST");
}



and it doesn't work :D
please tell me how to hide this action if another use program like www.sothink.comto view, and why that doesn't work if I do like that, thanks

Jubba
08-09-2003, 12:50 AM
Scoot: Actually, no. A message board with Flash isn't something that I want to tackle at the moment. It wouldn't be much more difficult, just much more in-depth. If you are looking for a message board that uses flash and PHP, I suggest you check out www.phpforflash.com

Aussie: The php script would name the variables for you, and then the Flash script would catch the variables and print them out. And saving them is the next part of the tutorial and its coming up. :) I think I'll write that part up tonight.

OKtrust: I'm not sure... thats more of a Flash targeting problem. Even if you put the code in a movie, in a movie, in a movie, someone, if they want it bad enough, is going to get it. If they want your code badly enough to download the SWF and have the decompiler, and then view your SWF with it, you should just let them have it because they are a lonely, desperate, sad, shell of a person. For them to know the name of your php page wouldn't really matter anyway, because they wouldn't be able to get a look at the code unless they had an FTP program and FTP access to your server....

Jubba
08-09-2003, 12:50 PM
This is part 4 of a multi-part tutorial. The parts are:

Part 1: A simple setup that will send variables from a Flash movie to a PHP script and then that PHP script will print the variables out.

Part 2: Sending variables from a Flash Movie to a PHP script, and then using that PHP script to send an e-mail.

Part 3: How to send a variable to PHP, and bring it back into Flash.

Part 4: Using LoadVars(). Sending variables from Flash to a PHP script. Saving those variables to a text file, then calling them back into Flash to form a guestbook/shoutbox/tagboard within Flash.

IMPORTANT: Now, this step gives us some options to work with. Since we are, possibly, going to be bringing large amounts of data into Flash from the PHP file we have one of two options:

1) bring the raw data string into Flash and then use Actionscript to format it to our liking.

2) Use PHP to format the string how we want it and then just pull it into Flash to display in the text box.

What I am going to do, is give you the basic set-up for the files and provide the files in an attachment, then at the end of the post I will provide the code to manipulate the string.

Be sure to read slowly because if you don't have a firm grasp on PHP and Flash string editing, you may get lost. If you don't understand this then go back and read the other tutorials before attempting this. If you still have questions then post in the Server-Side-Scripting Forum (http://www.kirupaforum.com/forums/forumdisplay.php?s=&forumid=11). And someone will be around to answer your questions. :thumb:

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Flash Player set-up
First you need to set up the input and dynamic text boxes. Create an Input box by using the "Text tool" In the text properties box, you must give them instance names. In this case we are using instance names instead of variable names because we are going to be using LoadVars() and using instance names is more up-to-date syntax, as well as more powerful with the LoadVars().

I gave the input box the instance name "sendVars" because that is the variable that we are going to be sending to the PHP script. The dynamic textbox has the instance name "recVars" because its going to be receiving the varables from the PHP script.

In my file (which you should download to get a better feel of how its set up) I have my two text boxes (one dynamic and one input) and a button that I named subBut because its the button I'm using to submit my variables. Now you are going to want to place the loadVars actionscript in the main timeline of the movie:

The code that I used looks like this:
subBut.onPress = function () {
sendlv = new LoadVars ();
loadlv = new LoadVars ();
loadlv.onLoad = function (success) {
if (success) {
trace ("Success!");
_root.myvar = this.myvar
}
else
{
recVars.text = "Error loading file.";
};
sendlv.sendVars = sendVars.text;
sendlv.sendAndLoad ("write2text.php", loadlv, "post");
sendVars.text = "";
recVars.text = "";
}

Now lets explain the code:
subBut.onPress = function () {
//This defines the MovieClip subBut
//as having button actions, and calls the function contained
//in the brackets everytime the user clicks on it.
}


// These lines simply define new LoadVars() objects
sendlv = new LoadVars ();
loadlv = new LoadVars ();

loadlv.onLoad = function (success) {
if (success) {
trace ("Success!");
_root.myvar = this.myvar
} else {
recVars.text = "Error loading file.";
}
};
//This function simply defines that onces the variables are loaded
//correctly the variable from the PHP file should be pointed to the
//dynamic text box

sendlv.sendVars = sendVars.text;
//Defines the variable we are sending to the PHP script
//as the text contained in the Input box "sendVars"
sendlv.sendAndLoad ("write2text.php", loadlv, "post");
//The script that sends and loads the variables
//"write2text.php" is our PHP file
//loadlv is our target to load the variables
//"post" is our method of loading the variables
sendVars.text = "";
recVars.text = "";
//these lines simply reset the text boxes to make it easier to type
//and read

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
PHP Page set-up
The PHP code is as follows:
<?

$sendVars = $_POST['sendVars'];

$file = "write2text.txt";

$fp = fopen($file, "a+");

$data = fread($fp, 80000);

ftruncate($fp, 0);

$new = $sendVars . ".:-:." . $data;

fwrite($fp, $new);

fclose($fp);

print "recVars=".$new;

?>

Now a quick explanation of the code:
$sendVars = $_POST['sendVars'];This line defines the variable $sendVars as the variable that we will be receiving from the Flash file. This is not always necessary because most server are set up differently, but it is good practice to always catch your variables this way, because your code will work no matter what server you are on.

$file = "write2text.txt"; This line just defines a variable with the string of our text file name. It makes the code easier to read.

$fp = fopen($file, "a+");This line opens the file for reading and writing and places the pointer at the beginning of the file.

$data = fread($fp, 80000); This line reads the contents of the file and saves it to a variable $data

ftruncate($fp, 0);This line deletes the file contents and cuts the file size to 0. This step isn't really necessary, but this is the method that I like to use.

$new = $sendVars . ".:-:." . $data; Here we define the variable $new as our Flash variable and our text file data with the string ".:-:." in between them. You will see why it is important to have something like that separating them once we get to the string manipulation later

fwrite($fp, $new);This writes the variable $new into the text file

fclose($fp);Closes the text file always make sure you close the file

print "recVars=" . $new;This prints out the variable in a form that Flash can read.

Thats pretty much it. This should give you a way to get started. I'll have the string formatting codes later on today :)

Don't forget the file attachment is below :)

And a big thanks to Ahmed who helped me with the loadVars() script because I am Flash MX illiterate


See the files in action: http://www.bluefinatlantic.com/egTest/php/write2text.swf

type in the top box and click the button and you will see all the entries from the text file :)

Cheers,
Jubs :crazy:

ehman
08-14-2003, 09:47 AM
very nice tut, just one question, how would i change it so that each time a new message is added it goes on a new line ?

I tried

$new = " $sendVars ..:-:.. <br> $data";

and 'render text as html' was enabled
but it dosent work

Jubba
08-14-2003, 11:29 AM
thats where the string formating comes in. I haven't had time to do that yet...

String.prototype.replaceS = function (str, rep, chr) {
var t = (chr < 0) ? this.substr(chr) : this.substr(0,chr);
var s = str.length;
var r = rep.length;
var p = t.indexOf(str);
while (p != -1){
t = t.substr(0,p) + rep + t.substr(p+s);
p = t.indexOf(str,p+r);
}
return (chr) ? (chr < 0) ? this.substr(0,this.length+chr)+t : t+this.substr(chr) : t;
}


recVars.replaceS(".:-:.", "<br>");



That is Senoculars prototype for replaceing a string with another string. That should get you what you want for now... This code should go in the main timeline. Put the actual prototype by itself, but put the

recVars.replaceS(".:-:.", "<br>");

in the onLoad command.

ehman
08-15-2003, 07:16 PM
Alright cool, btw cant wait for the next tutorial

I still dont get why this wont work

$new = " $sendVars ..:-:.. <br/>$data";

Isn't flash MX supposed to understand and process simple html tags ?

Anyway i think managed to do the new line thing (somewhat) by using a different php string replacement sccript, but it dosen't work exactly the way i want it to

I will try the script that you gave me

Keep up the good work

Jubba
08-16-2003, 12:42 AM
yes, but when you save that to the text file you mess up the PHP script's ability to read the textfile correctly. :)

OKtrust
08-17-2003, 02:06 PM
by the way, can we do this tutorial become a shout box or chat room ? but I don't know how to delete and limit the line of text :D

Jubba
08-17-2003, 06:40 PM
the best way to do that would be to check for those things on the Flash side of the program. And yes, you can turn this into a shoutbox.

If you wnat to learn about string formatting (limiting text, etc) post a thread in the Flash MX forum :)

ehman
08-21-2003, 10:34 AM
Originally posted by Jubba
yes, but when you save that to the text file you mess up the PHP script's ability to read the textfile correctly. :)

Ah but ofcourse :(

anyway check out this cool little chat i have been working on based on this tutorial
very simple chatbox application (http://www.atbcp.com/ehman/flashphp/api2.html)

Still needs a lot of improvements but Okturst yeah you can build something like a chat room or shout box based on this tut :}.

Jubba
08-21-2003, 11:07 AM
thats really cool. i'm glad you got it working. :)

Scootman
08-21-2003, 07:56 PM
or in your php you can just add "\n" at the end of the $new variable eh? like going

$new. = "\n";

would that work? cuz then when it gets added to the txt file it will be on a new line

Scootman
08-21-2003, 08:25 PM
hey jubba i uploaded your files to see if they worked on my server (which does support php) but it gave me a bunch of errors and i read on here before that it might have to be chmod'ed so i did that and i still got all these errors

Warning: chmod failed: Operation not permitted in /home/virtual/site17/fst/home/scootman/public_html/PHP/write2text.php on line 7

Warning: fopen("write2text.txt", "a+") - Permission denied in /home/virtual/site17/fst/home/scootman/public_html/PHP/write2text.php on line 9

Warning: fread(): supplied argument is not a valid File-Handle resource in /home/virtual/site17/fst/home/scootman/public_html/PHP/write2text.php on line 11

Warning: ftruncate(): supplied argument is not a valid File-Handle resource in /home/virtual/site17/fst/home/scootman/public_html/PHP/write2text.php on line 13

Warning: fwrite(): supplied argument is not a valid File-Handle resource in /home/virtual/site17/fst/home/scootman/public_html/PHP/write2text.php on line 17

Warning: fclose(): supplied argument is not a valid File-Handle resource in /home/virtual/site17/fst/home/scootman/public_html/PHP/write2text.php on line 19

the chmod line i added was

chmod($file, 0777);

because you said it needed to be set to 777 before so i dunno whats wrong... can you help? or anyone help?

ehman
08-22-2003, 01:22 AM
yeah scootman i used /n method, and it works but i had to put it in after it writes to the text file. $new. = /n dosent seem to work for me.
Anyway the php method is much simpler than all of that actionscript.

yeah you do have to chmod it 0777 in order for it to work because it needs to change the text file.
Try using your ftp client to chmod i dont see the need to use php (though i dont see how that why that would make a difference).
Also try using the name of the file insted of the variable

Scootman
08-22-2003, 01:39 AM
k ill try it... thanks.... and the \n thing uses backslash not foreward slash... and it should be in quotes... heh but it seems you figured it out

ehman
08-22-2003, 04:13 AM
oh whoops, of course i used "\n" , i dont know where /n came from, probably from being drunk anyway did you manage to fix the permissions thing

Scootman
08-22-2003, 01:27 PM
yeah i had to take out the chmod thingy cuz that was screwing it up and i just did it with the FTP.... its weird though... when i run it with IIS on localhost i have to leave the chmod in there... anyway i got it figured out... thanks for the tip

felipegm
09-22-2003, 01:57 PM
Hi,

How do I add the fone number and name to the message sent?

Also IŽd like the message to brake when the user brakes the lines.

thks

Krivanka
09-23-2003, 06:06 PM
Im trying to do something similar using php to send an email to the subscribe address of a mailing list. I have a button in flash with the following code:

on (release) {
if (email == "") {
stop();
} else {
loadVariables("mail.php", 0, "POST");
gotoAndStop(7);
}
}


and then the php code:

<?PHP

$Email_=_$_POST['email'];
$Subject_=_"Subscribe";
$Message_= "Subscribe";
$to = "stereotoxic-subscribe@krivanka.com";
$headers = "From: <$Email>\n";
mail($to, $Subject, $Message, $headers);
?>

But the mail is never getting sent. If anyone can help me troubleshoot this Id greatly appreciate it. Thanks.

Jubba
09-24-2003, 11:17 AM
Scoot: You can't chmod the file using the PHP script unless the folder your files are in is CHMODed. Its a security feature. I didn't realize that you guys were still posting in this thread. If you have a question post in the Server-side Scripting forum, I don't check this forum on a regular basis and this isn't really a thread for questions.

K: What is up with all the _ in your code?

Scootman
09-25-2003, 01:57 AM
heh i posted that a while back... i ended up figuring out how to do it... thanks though

volcomp
01-26-2005, 05:34 PM
Where are the files?

baddawg
05-17-2005, 06:08 PM
i am using flash mx 2004, i have made use of your code
but i get an error

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 1: Statement must appear within on handler
submit.onPress = function () {

Total ActionScript Errors: 1 Reported Errors: 1


and the sript is :
submit.onPress = function () {
getURL ("getVars.php", "_blank", "POST");
}



tel me what am i doing wrong ..

i am making a country map in flash , the button i use is a image (made to a symbole (button) )
by click it it wil send a variable to a php file , this variable i can then use in a search engine to look up all info of that variable (region, or city)

can some one help me out , or is it just the version of flash that i am using

amirag
05-18-2005, 01:18 PM
am using flash mx 2004, i have made use of your code
but i get an error

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 1: Statement must appear within on handler
submit.onPress = function () {
try to use this
on (press){
the rest of the code
}
instead of using function

baddawg
05-18-2005, 05:00 PM
try to use this
on (press){
the rest of the code
}
instead of using function

oke so much for the error
but it is still not loading
i have made print screen as following:
http://198pc197.sshunet.nl/map/problem.gif


as you cansee i put a value allready in the text area , this value i want to send to my php file
this wil become the variable then so that i can use for a search criteria

the code on my button is as following:
on(press){
loadVariablesNum("region.php", 1, "POST");
}

on (rollOut) {gotoAndPlay(10);

}

the text are is a dynamic input field
and i made to a movie symbole


i don't get error, but what am i doin wrong
please help


hellllllpppppp!!!!!!!!!!!

baddawg
05-22-2005, 01:29 PM
This is part 2 of a 3 part tutorial. The parts are:

Part 1: A simple setup that will send variables from a Flash movie to a PHP script and then that PHP script will print the variables out.

Part 2: Sending variables from a Flash Movie to a PHP script, and then using that PHP script to send an e-mail.

Part 3: Sending variables from Flash to a PHP script. Saving those variables to a text file, then calling them back into Flash to form a guestbook/shoutbox/tagboard within Flash.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Ok, this is basically a combination of the post above, and this thread that I created the other night about using the mail() function: Click Here! (http://www.kirupaforum.com/forums/showthread.php?s=&threadid=17313)

Since most of this is already explained in those two posts, this section of the tutorial is going to be small because it serves only as a link between those two. Here we go!

Flash Set-up

The only difference between this file and the file before is the script for the button. You set everything up the same way. Create the input text boxes and give them a suitable name. I gave my three input boxes the names "name", "email", and "message".

The code on the button changes a little because now, we don't want to open another page. We just want the e-mail to be sent when the user clicks the Flash button. So, we won't be using getURL() but instead we will use loadVariablesNum(). The code looks like this:

sendButton.onPress = function(){
loadVariablesNum("mailTut.php", 0, "POST");
}

this takes the variables from level "0" and sends them to the script contained in "mailTut.php" using the "POST" method.

PHP Set-up

Now, if you read thru those other two posts that I showed you, then you should have no problem understanding the rest of this post. If you didn't read thru them, then you still won't have a problem because its very simple. Here is the code:

<?

// Recieving and Creating Variables...
$Name = $_POST['name'];
$Email = $_POST['email'];
$Message = $_POST['message'];
$Subject = "Test E-mail Tutorial";
$Header = "From: $Name <$Email>";


//Performing Mail script...
mail($Email, $Subject, $Message, $Header);

?>

The first 5 lines of code are "Recieving and Creating Variables". This recieves the variables from the Flash movie and then creates the Subject and Header variables to be used in the mail() script.

The mail() script is then executed. I already explained all of this stuff in the other tutorial that can be found here: Click Here (http://www.kirupaforum.com/forums/showthread.php?s=&threadid=17313)

Ok thats its for this one.

Sorry, I had to take out the script in action link because the server that the script was set up on was taken down.
Cheers,
Jubs :geek:





as you cansee i put a value allready in the text area , this value i want to send to my php file
this wil become the variable then so that i can use for a search criteria

the code on my button is as following:
on(press){
loadVariablesNum("region.php", 1, "POST");
}

on (rollOut) {gotoAndPlay(10);

}

the text are is a dynamic input field
and i made to a movie symbole


i don't get error, but what am i doin wrong
please help


hellllllpppppp!!!!!!!!!!!

gaurab
11-21-2005, 05:31 AM
hello sir ,iam a professional web developer working in nepal.I tried your method to send variable from flash to php,i have defined the method post in it,but it is transfered only in get method why?please reply me soon.

gaurab
11-21-2005, 05:34 AM
hello sir ,iam a professional web developer working in nepal.I tried your method to send variable from flash to php,i have defined the method post in it,but it is transfered only in get method why?please reply me soon.
i have not tried it online.

malx
12-28-2005, 04:29 PM
Can anyone download those files? I can't seem to find the download link.

-Joey Avino

Slazareth
01-03-2006, 01:38 PM
Yea, where'd the downloads go? Great work btw. Well written.

hollyhogan
08-14-2006, 07:54 AM
lol

mitooquerer
11-05-2006, 06:08 PM
Yeah, where are the files??? I am reading the tutorial in 2006, it seems the files dissapeared...

Digitalosophy
11-07-2006, 02:58 PM
The files aren't coming back anytime soon.

avance
11-17-2006, 11:51 AM
hi, i have tried the script posted by baddawg and 1st i get an error telling me that the button script has to be in an on event handler. so i changed that as follows

on (release) {
loadVariablesNum("http://bmbpl.thetestingplace.co.uk/text/senttext.php", 0,"POST");
nextFrame();
}

i used the following php script to email it to myself

<?

// Recieving and Creating Variables...
$Opinion = $_POST['opinion'];
$Subject = "Test E-mail Tutorial";
$toEmail = "a_jones10@hotmail.com";


//Performing Mail script...
mail($Opinion);

?>

Is there a problem with either script? I'm new to the programming world so somebody please please help.

Cheers

lancerawks
01-09-2008, 08:12 PM
could you make a download flash file of your tutorial?

AstralAron
02-12-2008, 06:30 AM
where do i download the FLA ? i cannot get this to work.

i can get the variables to the php file in the first part of the tutorial:
submit.onPress = function () {
getURL ("getVars.php", "_blank", "POST");
}


but cannot get the
mc_button_submit_vars.onPress = function ()
{
loadVariablesNum ("kirupa_tutorial.php", 0, "POST");
};

to work

or the final one either..

im using flash cs3 actionscript 2.0 or flash 8 professional

AstralAron
02-12-2008, 06:34 AM
no files??? what good is this... the code has errors

belox89
02-20-2008, 11:20 AM
Hello,
I figured out what was wrong with the script after a 5-hour struggle. If anyone wants to know, email me at paul_raubic@hotmail.com.

prg9
02-22-2008, 02:37 AM
Hello, I figured out what was wrong with the script after a 5-hour struggle. If anyone wants to know, email me at paul_raubic@hotmail.com.

Since it was originally posted here, why do you not wish to do the same? If it helped you perhaps you could help others, that was the intent of the Jubba when he made a 3 part tutorial ;-). From the recent posts I am sure people are interested, and will be in the future also.

So why not post your solution here to help others? :h:

hammad
04-10-2008, 07:46 PM
Thanks

creativeFuzion
04-12-2008, 10:04 AM
Hello,
I figured out what was wrong with the script after a 5-hour struggle. If anyone wants to know, email me at paul_raubic@hotmail.com.

Go on, post your ideas! It's not a big deal, I'd rather not have to email and wait for a reply if I were anyone else who is interested in this. And posting the information here one time would save you having to explain to multiple people via email how it all works.

-Philip

ThaJock
05-03-2008, 11:53 PM
Can anyone tell me how to get a line break on the $Message variable so that the $Name and $Email will appear on different lines?

<?

// Recieving and Creating Variables...
$Name = $_POST['name'];
$Email = "josh@williamsfp.com";
$Message = "$Name" ./n. "$Email";
$Subject = "New Web Lead";
$Header = "From: $Name <$Email>";


//Performing Mail script...
mail($Email, $Subject, $Message, $Header);

?>

ThaJock
05-08-2008, 03:36 PM
OK, I followed these instructions step by step and got nothing. Is there more to the scripts both AS and PHP than what is in the tutorial?

Alex Lexcuk
05-13-2008, 02:49 PM
PHP->FLASH
<?php
//GaleryScoresText.php.
//In flash out
echo "GaleryScoresText=HELO!!!!!!";
?>


//fla
on (press)//button code
{
url="http://murmadillo.tut.su/submit_score.php";
my_load_vars=new LoadVars();
my_load_vars.load(url);
my_load_vars.onLoad = function()
{
_root.memo_1.text=my_load_vars.HighScoresText;//Dynamic text
}

}


FLASH->PHP
on (press)//button code
{
url="http://murmadillo.tut.su/submit_score.php";
//load_vars
var my_lv:LoadVars = new LoadVars();
var my_ret:LoadVars = new LoadVars();

my_lv.playerName = "HELLO";
my_lv.playerScore = "Alex Lexcuk";
my_lv.sendAndLoad(url, my_ret, "GET");
}

//end



//php treason my_file.txt reason FLASH VAR
<?php

$result=$result.$_GET['playerName']." ";
$result=$result.$_GET['playerScore'];

echo $result;

$fh=fopen("my_file.txt","w");

fwrite($fh,$result);

fclose($fh);

//echo $buff;
?>


//fla
on (press)//button code
{
url="http://murmadillo.tut.su/submit_score.php";
// load_vars
var my_lv:LoadVars = new LoadVars();
var my_ret:LoadVars = new LoadVars();

my_lv.playerName = "Alex";
my_lv.playerScore = "This Mega GOOD";
my_lv.sendAndLoad(url, my_ret, "GET");
_root.memo_1.text = "Send...";
my_ret.onLoad = function()
{
_root.memo_1.text ="Well done.";
}


}


<?php
session_start();
$result_name=strip_tags($_GET['playerName']);//chaccer killer
$result_score=strip_tags($_GET['playerScore']);//crack killer
//that time?
$result_time = date("d.m.Y H:i");
//example 07.09.2008 08:50


//create array
$split_data=$result_name.'&'.$result_score.'&'.$result_time."\n";
echo $result;

$fh=fopen("my_file.txt","a+");//add in end of file

fwrite($fh,$split_data);//write file
//echo $buff; //in flash out
fclose($fh);//close file my_file.txt

?>

Digitalosophy
05-16-2008, 01:32 PM
no files??? what good is this... the code has errors

It's been proven to be very good and help many members. If you notice the post date "03-16-2003, 08:42 PM" maybe you can understand why there are no files.