View Full Version : Send data from flash to php/javascript or vice versa
jerome.chevreau
10-24-2008, 06:55 AM
Hi everybody,
I was wondering if anyone could help me learn wokring with flash, javascript and even php. I would like to be able to send my data from my flash app to a php file or even to javascript to poppulate a html or a text file. And obviously the opposite, sending data from html to flash with the use of javascript and/or php.
Please please, does anybody can help me find tutorials in order to learn.
Thanks for any help.
Jerome
Hi,
You will need to understand the use of the loadVars class as well as the sendAndLoad methods in Flash. You will probably want to go with PHP as it is a server side language and adept at data transfer.
The basics...
//create a loadVars object to BOTH send and receive data
myVars=new LoadVars();
//create a load check function to tell when the object has
//populated withnew data
myVars.onLoad=function(success){
if(!success){
trace("Failed to load!"){
}else{
//establish and retrieve data here
myVariable=this.setVariable;
}
}
}
Then, from a button event or other....
myButton.onRelease=function(){
myVars.sendAndLoad("myFile.php", _root.myVars,"POST")
}
Writing data to a text file would be done with PHP. Something like...
PHP code...
<?
//Register variables sent from the flash movie
$myFileName=$_POST["myFileName"];
$article=$_POST["article"];
//open the text file,write the data sent,close the file
$fp = fopen ("$myFileName", "w+");
fwrite($fp,"$article");
fclose($fp);
//check success and echo message back to flash
if ($fp) {
echo ("&msg=Save Successful!&name=$name&myTextSave=$myTextSave");
} else {
echo ("&error=OK&msg=Save unsuccessful!...an error occurred!");
}
?>
Regards
NTD
Powered by vBulletin™ Version 4.1.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.