AMFPHP+FLEX简单应用

首先到AMFPHP官方去下载安装包:http://www.amfphp.org/

下载完后,解压文件并把文件放到服务器下。

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

显示上面信息,说明安装成功。所有的PHP文件,都要放到amfphp/services/下。

例如创建个MyPHP/HelloWord.php文件:

http://localhost/amfphp/browser/ 中会看到你刚创建的文件,并测试该文件是否正确。

创建FLEX项目:

创建项目时,要确认是否加入了RPC.SWF模块,并在项目属性的Flex Complier里加入 -services "services-config.xml"

并在src下创建services-config.xml文件

其中<channel ref="my-amfphp"/>的ref必须要于channel-definition 的id一样。

创建mxml文件,调用RemoteObject

view plaincopy to clipboardprint?
<mx:RemoteObject id="myService" destination="amfphp"    showBusyCursor="false" source="MyPHP.HelloWord" fault="onFault(event)">  
   <mx:method name="sayHello" result="onResult(event)"/>  
</mx:RemoteObject> 
<mx:RemoteObject id="myService" destination="amfphp"    showBusyCursor="false" source="MyPHP.HelloWord" fault="onFault(event)">
   <mx:method name="sayHello" result="onResult(event)"/>
</mx:RemoteObject>

destination 属性需要与services-config.xml的配置<destination id="amfphp">相对应
source 属性会找到amfphp/services/MyPHP/HelloWord.php文件,也就是刚才所创建的PHP文件。
节点<mx:method/>定义调用的方法:name="sayHello"为HelloWord里的sayHello方法,直接对应。             result接受返回值。
view plaincopy to clipboardprint?
private function onResult(evt:ResultEvent):void{  
      trace(evt.result.toString());  

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值