首先到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());
}