AMFPHP教程之安装及使用

下载解压到你的站点目录下,我这里的路径是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 this message. This confused people so this is the new behaviour starting from 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.简单的一个输出实例:
新建Flash cs3文件
动作面板输入:
var gates:String="http://localhost/amfphp/gateway.php";//网关地址
var nc:NetConnection=new NetConnection();//链接对象,有点像数据库里的连接对象,呵

//处理结果响应的,Responder,2个参数回调(callback)函数,第一个正确结果响应,后面第2个参数可选,响应错误状态
var rp:Responder=new Responder(handleResult);
function handleResult(rs:Object):void
{
        trace(rs);
}

nc.connect(gates);
nc.call("Welcome.hi",rp,"张三");

对于服务无法是一个php的类,里面定义了一些方法供调用。
<?php
class Welcome
{
        public function hi($usr)
        {
                return "欢迎你:".$usr;
        }
}
?>
名字保存为Welcome.php.保存到amfphp\services目录里,然后我们通过服务管理面板就可以看到我们的服务Welcome了
运行下吧。
当然可以加上第二个参数:
var rp:Responder=new Responder(handleResult,handleError);
function handleError(rs:Object):void
{
        for(var key in rs)
        trace(key+"====>"+rs[key]);
}
nc.call("Welcome.h0",rp,"张三");
调用一个不存在的方法
我的机子输出:
line====>86
description====>The method  {h0} does not exist in class {Welcome}.
level====>User Error
details====>C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\amfphp\core\shared\app\BasicActions.php
code====>AMFPHP_INEXISTANT_METHOD

你可能感兴趣的:(C++,c,PHP,C#,Flash)