AMFPHP

9 篇文章 0 订阅

下载地址:http://sourceforge.net/projects/amfphp/files/amfphp/

 

转自:http://www.cnblogs.com/xxcainiao/archive/2008/04/17/1158606.html

 

 

 

 

不想传递拆分字符串,解析串行XML了吧?
厌烦JSON了?
试试AMF吧,传送多种数据格式。
首先下载AMFPHP(本教程使用1.9BETA2)你可以选择其他版本  在这里选择下载

下载后,解压缩,把文件夹中的amfphp文件夹拷贝到 APACHE服务器的网站根目录。
然后打开浏览器,输入
http://localhost/amfphp/gateway.php    确定
如果提示:

amfphp and this gateway are installed correctly. You may now connect to this gateway from Flash.

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文件夹,进入SERVICES文件夹,新建一个PHP文件命名为HELLOWORLD.php
拷贝以下代码:

<?php
class HelloWorld
{
     function HelloWorld()
    {
         $this->methodTable =  array
        (
            "say" =>  array
            (
                "access" => "remote",
                "description" => "Pings back a message"
            )
        );
    }
 
     function say( $sMessage)
    {
         return 'You said: ' .  $sMessage;
    }
}
?>

保存!
在浏览器地址栏输入
http://localhost/amfphp/browser/
回车
AMFPHP的项目管理器:

单击 HelloWorld
看到一下内容,就是HELLOWORLD项目具体内容:

在sMessage输入内容(比如"xiaoxiaocainiao"),  单击call按钮:

看到页面下方的提示结果:

好了,你已经初步学会安装AMFPHP并使用了,具体的语法,函数,还需要查看一下官方的文档啦。

下面一起来做一个FLASH通过AMFPHP和PHP交互的小例子:

到这里下载AMFPHP for FLASH8的组件,如果你使用其他版本,请到这里选择下载:http://www.adobe.com/products/flashremoting/downloads/components/

下载后安装,完毕后打开FLASH ,查看 “窗口|公用库|Remoting”就可以看到AMFPHP的组件了。


新建立一个工程,拖一个RemotingClasses组件到舞台的任何地方,再拖一个List组件,命名为myls,拖一个Button组件,命名为"mybt"
在第一帧的代码行复制以下代码:

import mx.remoting.*;
import mx.rpc.*;
import mx.utils.Delegate;
import mx.remoting.debug.NetDebug;
var gatewayUrl:String = "http://localhost/amfphp/gateway.php";
var service:Service;
NetDebug.initialize();
service =  new Service(gatewayUrl,  null, "PersonService");
function getPerson() {
    trace("getPerson");
     var pc:PendingCall = service.getPerson();
    pc.responder =  new RelayResponder( this, "handleGetPerson");
}
function handleGetPerson(re:ResultEvent) {
    trace("handleGetPerson");
    trace(re.result.getItemAt(0).name);
    _root.mytree.dataProvider = re.result;
    _root.mydg.dataProvider = re.result;
}
function onClick() {
    getPerson();
}
mybt.addEventListener("click", Delegate.create( this, onClick));

在AMFPHP的SERVICES文件夹下新建一个文件,命名为PersonService.php
复制一下内容到PersonService.php

<?php
class PersonService
{
     function PersonService()
    {
         $this->methodTable= array(
            "getPerson"=>
                 array(
                   "access"=>"remote"    
                )
        );
     mysql_connect('localhost','root','wuliqunao');
         mysql_select_db('test');
    }
     function getPerson()
    {
          $sql= sprintf("SELECT * FROM persons");    
            $query= mysql_query( $sql);
          return  $query;
    }
}
?>

好了,发布你的程序,单击Button按钮,看到结果:


当然了,你的本机需要有个MYSQL数据有,里面简历一个test数据库,这个库里面创建一个persons数据表,表里2个字段,一个是name,一个是age.(表告诉我,你搞不好这个库啊,搜一个MYSQL数据库入门教程,一下就知道啦。)

好了,大功告成,开始学习AMFPHP之路吧~~~~

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值