In this tutorial I will show you how to send som data from flash to PHP, encrypting it and sending the answer back again. If you just want the code and no explanation jump to the last page...
I'm just going to get started, so first get create a new flash document, than open the actionspanel. Then lets start coding:
var send:LoadVars = new LoadVars;
var receive:LoadVars = new LoadVars;loadVars.nameOfVariable = valueOfVariable;Here you need to replace the loadVars with the loadVars (in this case send), the nameOfVariable with a variablename (could be nearly anything, but for this case lets use toPHP) and the valueOfVariable with the value of a the variable or the data to send in other words... so lets type
send.toPHP = "test";Good, the next thing to be done is to tell what to do when flash receives the answer, or in other words when the receive loads the content of a site. To do so we use
loadVars.onLoad = function(){
//Here goes the code to execute when it loads
}receive.onLoad = function(){
encrypted = this.toFlash;
trace(encrypted);
}Than we only need to tel flash to load the server script... To do so we use:
loadVars.sendAndLoad("serverScript",anotherLoadVars,"method");send.sendAndLoad("encrypt.php",receive,"POST");Very good tutorial, but you got to be carefull about the folders. I had my animation in root/page/anim and my pages where functioning in root/page and i placed the .php files in the /anim folder cause i thought that it may read from there WRONG! the flash reads from where the page containing the movie is running, in this case root/page , so i moved the file from root/page/anim to root/page and problem solved. Keep in mind that my .swf file was still in /anim.
have a nice day!
Well... This won't be a problem if you add absolute URLs... If your php-file is "/root/admin/php/phpfile.php" and your domain-name is "http://www<dot>somdomain<dot>net" then you could use the path "http://www<dot>somdomain<dot>net/root/admin/php/phpfile.php".
I think you also can use juse "/root/admin/php/phpfile.php" but I'm not shure about that...
Alxandr
Easy to understand, easy to get working. Thanks for the tutorial. After many problems I finally figured out that you need to put an ampersand & in the php code before the first variable when it returns it to the flash.