I've been reading few articles, tutorials and followed all their explanations, but somehow I have to be misunderstanding something, because my code does not work the proper way.
The thing is that I have a an SWF with a triangle called PLAYER, x position = 60 and y position = 120.
The FlashMovie also contains a star Movie Clip (called CONTROL) that works as a listener.
It is supposed that when I click over the star, AS3 must send the name and position of the triangle to my save.php file.
Then, my save.php file must catch and send the POST variables to my MYSQL database.
AS3 CODE
Expand|Select|Wrap|Line Numbers
- //----------------------------------
- //Import Libraries
- //----------------------------------
- import flash.net.*;
- import flash.events.*;
- //----------------------------------
- //var declarations || The Flash movie is loaded in http://www.erimm.com/index.php
- //----------------------------------
- var url:URLRequest=new URLRequest("http://www.erimm.com/save.php");
- var variables:URLVariables=new URLVariables();
- var loader:URLLoader=new URLLoader();
- //----------------------------------
- //trigger listener creation
- //----------------------------------
- CONTROL.addEventListener(MouseEvent.CLICK,insertar);
- //----------------------------------
- //loader listener creation
- //----------------------------------
- function insertar(e:MouseEvent){
- loader.addEventListener(Event.COMPLETE, carga);
- loader.load(url);
- }
- //----------------------------------
- //sending variables
- //----------------------------------
- function carga(e:Event) {
- variables.user="PLAYER";
- variables.xpos= PLAYER.x;
- variables.ypos= PLAYER.y;
- url.data=variables;
- url.method=URLRequestMethod.POST;
- loader.dataFormat = URLLoaderDataFormat.VARIABLES;
- sendToURL(url);
- }
Now the Save.php CODE
Expand|Select|Wrap|Line Numbers
- <?php
- //-----
- // Conex Vars Info
- //-----
- $host = "XXXXXXX"; //Hidden due to security reasons
- $username = "XXXXXXX"; //Hidden due to security reasons
- $pass = "XXXXXXXX"; //Hidden due to security reasons
- //-----
- // Conex creation
- //-----
- $dbase = "BLABLA";
- $conex = mysql_connect($host,$username,$pass);
- mysql_select_db($dbase,$conex);
- //-----
- // Catching Vars
- //-----
- $user = $_POST['user'];
- $xpos = $_POST['xpos'];
- $ypos = $_POST['ypos'];
- //-----
- // Sending Vars to DB in orther to update $user row (PLAYER row)
- //-----
- $consulta = "UPDATE users SET xpos=$xpos, ypos=$ypos WHERE user=$user";
- mysql_query($consulta,$conex);
- ?>
If I'm not wrong, it must be working the following way.
Index.php-----[JUEGO.SWF]----vars---->Save.php---->MYSQL
Can anybody help me with this?
Thank you so much, guys!
Eri.