package {
// required for flash file and output display
import flash.display.MovieClip;
import fl.events.*;
import flash.events.*;
import flash.utils.describeType;
// required to send/recieve data over AMF
import flash.net.NetConnection;
import flash.net.Responder;
// Flash CS3 Document Class.
public class Main extends MovieClip {
private var gateway:String = "http://localhost/amfphp/gateway.php";
private var connection:NetConnection;
private var responder:Responder;
public function Main() {
trace("AMFPHP HelloWorld Example");
// Event listner for buttons
send_btn.addEventListener(MouseEvent.CLICK, sendData);
fault_btn.addEventListener(MouseEvent.CLICK, faultServer);
// Responder to handle data returned from AMFPHP.
responder = new Responder(onResult, onFault);
connection = new NetConnection;
// Gateway.php url for NetConnection
connection.connect(gateway);
}
// Method run when the "Send To Server" button is clicked.
public function sendData(e:MouseEvent):void {
trace("Sending Data to AMFPHP");
// Get the data from the input field
var params = server_txt.text;
// Send the data to the remote server.
connection.call("HelloWorld.say", responder, params);
}
// Method run when the "Fault Server" button is pressed.
public function faultServer(e:MouseEvent):void {
trace("Faulting AMFPHP");
// Make a call to a service that does not exist.
connection.call("BadClass.noMethod", responder, "no paramaters");
}
// Handle a successful AMF call. This method is defined by the responder.
private function onResult(result:Object):void {
response_txt.text = String(result);
}
// Handle an unsuccessfull AMF call. This is method is dedined by the responder.
private function onFault(fault:Object):void {
response_txt.text = String(fault.description);
}
}
}
在这个示例中String(fault.description)返回了错误信息
但是AMFPHP好像没有文档介绍fault这个对象到底有几个值,然后我就
for(var o:Object in fault){
trace(o);
}
然后得到这几个属性
description=The class {HelloWorld} could not be found under the class path {D:\PHPnow\htdocs\amfphp\services\/HelloWorld.php}
level=User Error
details=D:\PHPnow\htdocs\amfphp\core\shared\app\BasicActions.php
line=33
code=AMFPHP_FILE_NOT_FOUND
回复Comments
作者:
{commentrecontent}