2009-07-02 30 views
0

如何通过这个流程的信息:如何连接这3种编程语言?

闪存(AS3) - > PHP,使用XML - >数据库(MySQL的)

任何人都可以写一个简单的代码?

谢谢。

+0

其实XML不是编程语言,它是标记语言。 – zinovii 2009-07-02 05:10:03

回答

0

WebService SOAP/WSDL怎么样?

所以你可以在php上提供web服务,并通过调用一些webservice方法从Flex/AS3/Flash发送信息,然后将它存储到mysql数据库中。

Flex有WebService类,所以在客户端调用随着服务器的方法是一样容易:

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); 

在PHP一边,我敢肯定,有十几家图书馆提供SOAP/WSDL。

1

如果您尚未绑定使用XML,则可能需要使用AMF进行调查。有许多针对PHP的AMF的OSS实现,从明显名为amfphpZend Framework中的实现。希望有经验的人会来,并提供更好的答案。

0

我会推荐使用amfPHP从通过php传递给Flash的MySQL数据库获取信息。与使用php以xml格式输出数据库结果相比,它更简单,更快速,更易于使用。基本上你用amfPHP做的是你可以使用LocalConnection类从flash直接调用php函数。

我会简化一些代码来说明它是如何工作:

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

所以基本上你将调用PHP函数闪光灯,并且还可以将数据返回到藏汉闪烁。

这只是为了说明amfphp是如何工作的。这并不意味着是一个完整的代码示例。只是提供一个简要的想法。

想一想,如果你认为它看起来很有趣去下载amfphp并尝试一下吧!你不会失望。