amfphp本质也没什么神秘的。就是把服务器端php的参数处理封装了下,让flex客户端可以通过简单的指定类名、方法名、参数来获得服务器端返回结果。
amfphp官方网站:
http://www.amfphp.org/
下载解压到你的站点目录下,我这里的路径是http://localhost/amfphp/
地址栏输入:http://localhost/amfphp/gateway.php,显示如下:
amfphp and this gateway are installed correctly. You may now connect to this gateway from Flash.
AMF C Extension is loaded and enabled.
Note: If you're reading an old tutorial,it will tell you that you should see a download window instead of thismessage. This confused people so this is the new behaviour startingfrom amfphp 1.2.
View the amfphp documentation
Load the service browser
说明amfphp已经安装成功了。
输入http://localhost/amfphp/browser/
我们可以打开控制台,管理我们的service.
对于中文的乱码问题,可以试试下面的2句(加到gateway.php里):
$gateway->setCharsetHandler("iconv", "UTF-8", "UTF-8");
$gateway->setCharsetHandler("iconv", "GB2312", "GB2312");
1.简单的一个输出实例:
新建flex bulider的MXML Application文件,建立一个文本框组件和按钮组件,按钮点击时,调用felx的callAmfPHP方法,文本框内容作为参数传入。
复制代码
服务端是一个php的类,里面定义了一些方法供调用。
复制代码
名字保存为Welcome.php.保存到amfphp\services目录里,然后我们通过服务管理面板就可以看到我们的服务Welcome了
运行下吧。
amfphp官方网站:
http://www.amfphp.org/
下载解压到你的站点目录下,我这里的路径是http://localhost/amfphp/
地址栏输入:http://localhost/amfphp/gateway.php,显示如下:
amfphp and this gateway are installed correctly. You may now connect to this gateway from Flash.
AMF C Extension is loaded and enabled.
Note: If you're reading an old tutorial,it will tell you that you should see a download window instead of thismessage. This confused people so this is the new behaviour startingfrom amfphp 1.2.
View the amfphp documentation
Load the service browser
说明amfphp已经安装成功了。
输入http://localhost/amfphp/browser/
我们可以打开控制台,管理我们的service.
对于中文的乱码问题,可以试试下面的2句(加到gateway.php里):
$gateway->setCharsetHandler("iconv", "UTF-8", "UTF-8");
$gateway->setCharsetHandler("iconv", "GB2312", "GB2312");
1.简单的一个输出实例:
新建flex bulider的MXML Application文件,建立一个文本框组件和按钮组件,按钮点击时,调用felx的callAmfPHP方法,文本框内容作为参数传入。
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
- <mx:TextArea id="amfphptest" width="200"/>
- <mx:Button label="call amfphp" click="callAmfPHP(amfphptest.text)" />
- <mx:Script>
- <![CDATA[
- import flash.net.Responder;
- import flash.net.NetConnection;
- private var gateway_url:String = "http://localhost/amfphp/gateway.php"; //网关地址
- private var geteway_conn:NetConnection = new NetConnection(); //网络链接对象,有点像数据库里的连接对象
- //处理结果响应的,Responder,2个参数回调(callback)函数,第一个正确结果响应,后面第2个参数可选,响应错误状态 ,str是要传的参数,多个参数可以继续加,以逗号隔开
- public function callAmfPHP(str:String):void
- {
- geteway_conn.connect(gateway_url);
- geteway_conn.call("HelloWorld.eb163say", new Responder(onResult, onFault), str); //调用amp服务器端的HelloWorld类的eb163say方法
- }
- private function onResult(result:Object):void //获得反馈结果成功时
- {
- amfphptest.text = result.toString();
- }
- private function onFault(fault:String):void //获得反馈结果失败时
- {
- amfphptest.text = fault;
- }
- ]]>
- </mx:Script>
- </mx:Application>
- <?php
- class HelloWorld
- {
- public function say($sMessage)
- {
- return 'eb163.com say: welcome,' . $sMessage;
- }
- }
- ?>
运行下吧。