当前位置: 首页 > 工具软件 > AMFPHP > 使用案例 >

AMFPHP调用方法

廖令
2023-12-01

AS2.0
==============================================================================
var gatewayUrls:String = "http://localhost/amfphp/gateway.php";
//这个地址根据你的本地或远程服务器地址而定
///login//
var Nc:NetConnection = new NetConnection();
Nc.connect(gatewayUrls);
var obj:Object = new Object();
obj.onResult = function(usecs) {
trace(usecs);
};
Nc.call("PHP类.函数名", obj, 参数1);

AS3.0
==============================================================================
package {
import flash.display.MovieClip;
import fl.events.*;
import flash.events.*;
import flash.net.NetConnection;
import flash.net.Responder;
public class Main extends MovieClip {
   private var gateway:String = "
http://localhost/amfphp/gateway.php";
                //amfphp 网关文件地址
   private var connection:NetConnection;
   private var responder:Responder;  
   public function Main() {     
    responder = new Responder(onResult, onFault);                     
    connection = new NetConnection;   
    connection.connect(gateway);
   }  
   public function sendData(e:MouseEvent):void {   
    connection.call("PHP类.函数名", responder, 参数1);
   }   
   private function onResult(result:Object):void {
                        //成功返回
    trace(String(result));
   }  
   private function onFault(fault:Object):void {
    trace(String(fault.description));
    //调出错误信息
   }
}

note:
     php文件格式:

<?php
class HelloWorld
//类
{
    public function say($sMessage)
    //函数
    {  
        return 'You said: ' ."我只能帮到你这里了";
    }
}
?>

 类似资料: