AS3, PHP & MySQL not Loading...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Eri Jhon

    AS3, PHP & MySQL not Loading...

    I need help with few problems trying to connect my .SWF in AS3 to my MySQL DB through PHP.

    I've been reading few articles, tutorials and followed all their explanations, but somehow I have to be misunderstandin g 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
    Code:
    //----------------------------------
    //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);
    }
    Up to here, AS3 must be loading my save.php file POSTING the variables.user .xpos and .ypos.

    Now the Save.php CODE
    Code:
    <?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);
    ?>
    The movie is loaded in a different page than Save.php. It is index.php, with a title and few examples i did.

    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.
Working...