如何在此流程中传递信息:
Flash(AS3) - > PHP,使用XML - >数据库(MySQL的)
有人可以为此编写一个简单的代码吗?
感谢。
答案 0 :(得分:2)
http://www.kirupa.com/developer/actionscript/flashphpxml_integration.htm
这将告诉您开始时需要知道的大部分内容。
答案 1 :(得分:1)
如果您还没有使用过XML,则可能需要考虑使用AMF。有许多针对PHP的AMF的OSS实现,从明显命名的amfphp到Zend Framework中的实现。希望有经验的人会出现并提供更好的答案。
答案 2 :(得分:0)
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。
答案 3 :(得分: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.
所以基本上你会在flash中调用php函数,你也可以将数据返回到flash中。
这只是为了说明amfphp的工作原理。它并不意味着是一个完整的代码示例。只是简单介绍一下。
考虑一下,如果你认为它看起来很有趣,请下载amfphp并尝试一下!你不会失望。