【问题标题】:How to connect these 3 programming languages?如何连接这 3 种编程语言?
【发布时间】:2009-07-02 04:27:18
【问题描述】:

如何在这个流程中传递信息:

Flash(AS3) -> PHP,使用 XML -> 数据库(mysql)

谁能为此写一个简单的代码?

谢谢。

【问题讨论】:

  • 其实 XML 不是编程语言,它是标记语言。

标签: php mysql xml actionscript-3


【解决方案1】:

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

这将告诉您开始时需要了解的大部分内容。

【讨论】:

  • 好吧,该链接使用的是“传递 url 变量”而不是 xml。这不是我想要的,但感谢您的链接
  • @jingleboy:那么,您可能应该更具体地说明您想要什么。
【解决方案2】:

如果您还没有使用 XML,您可能想考虑使用 AMF。有许多 AMF for PHP 的 OSS 实现,从明显命名的 amfphpZend Framework 中的实现。希望有这方面经验的人能过来,提供更好的答案。

【讨论】:

    【解决方案3】:

    WebService SOAP/WSDL呢?

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

    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。

    【讨论】:

      【解决方案4】:

      我建议使用 amfPHP 从 MySQL 数据库中获取信息,并通过 php 传递给 Flash。它比使用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. 
      

      所以基本上你会在flash中调用php函数,你也可以将数据返回到flash中。

      这只是为了说明一点 amfphp 的工作原理。它并不意味着是一个完整的代码示例。只是提供一个简短的想法。

      想一想,如果你觉得它看起来很有趣,那就去下载 amfphp 试试吧!你不会失望的。

      【讨论】:

        猜你喜欢
        • 2017-05-27
        • 2018-02-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-05
        • 1970-01-01
        • 2014-02-11
        相关资源
        最近更新 更多