views:

249

answers:

4

How to pass information in this flow:

Flash(AS3) -> PHP, using XML -> Database(mysql)

Can anyone write a simple code for that?

Thanks.

+2  A: 

http://www.kirupa.com/developer/actionscript/flashphpxml_integration.htm

This will tell you most of what you need to know to get started.

Travis
well, that link is using "pass url variables" not xml. Its not what I wanted, but thanks for the link though
jingleboy99
@jingleboy: You should probably be more specific as to exactly WHAT you want, then.
musicfreak
A: 

What about WebService SOAP/WSDL?

So you can provide web service on php and send information from Flex/AS3/Flash by calling some webservice method and then store it into mysql db.

Flex has class WebService, so on client side to call server method is as easy as:

var webService:WebService = new WebService();
webService.wsdl = "http://yoursite.com/webservice.wsdl";
webService.loadWSDL();
webService.this_is_method_from_php_server(your_object_serialized_as_xml);

On PHP side I'm sure there are dozen libraries to provide SOAP/WSDL.

zdmytriv
+1  A: 

If you're not already tied to using XML, you might want to look into using AMF. There's a number of OSS implementations of AMF for PHP, from the obviously named amfphp to an implementation in the Zend Framework. Hopefully somebody with experience here will come along and provide a better answer.

Sean McSomething
A: 

I would recommend using amfPHP to get information from a MySQL database passed to Flash through php. It is simpler, faster and easier to use than using php to output the database result in xml. Basically what you do with amfPHP is that you can call php functions directly from flash using the LocalConnection class.

I'll simplify some code to illustrate how it works:

//PHP code
//Here's you main php class which all the sql commands will be called

    class Main{
        public function saveUser($username, $password){
            //I'll send in the username and password to insert it into the users column
            $this->db->query("INSERT INTO users VALUES ($username, $password)");
            //I'm using the MDB2 library for sql queries, 
            //you write less code when doing queries.
        }
    }

    //Actionscript 3 code

    //To pass parameters to my php function I have to make an array.
    var amfParameters:Array = [];
    amfParameters['username'] = "richard";
    amfParameters['password'] = "123123";

    //Then create a localconnection which will connect to amfphp.
    var localConnection:LocalConnection = new LocalConnection();
    localConnection.connect(gatewayURL); //gatewayURL is the url to the gateway amfphp file
    localConnection.call("testproject.Main.saveUser", loaderResponder, amfParameters);
    //testproject.Main.saveUser is the path for our Main.php file and saveUser is the function
    //loaderResponder is a Responder class which handles the callback from amfphp.

So basically you will call the php function in flash, and you can also return data to flash aswell.

This is just to illustrate a little bit of how amfphp works. It's not meant to be a complete code sample. Just to give a brief idea.

Think about it and if you think it looks interesting go and download amfphp and try it out! You won't be dissappointed.

Ancide