1

在尝试连接到外部文件时,我无法正确识别何时未建立连接。如果我打开 localhost(即 config.gateway1),它工作正常,但如果我关闭服务器,我只会收到一个错误:

“错误打开 URL 'http://localhost/amfphp/gateway.php'”

我已经尝试在连接和呼叫上设置尝试捕获。我还设置了一个事件监听器,它应该调用一个 onFailure 函数(此时它只是跟踪失败)。当我拨打电话时似乎发生了错误,但它不起作用......但我似乎无法指示发生错误时会发生什么。

    var gateway1:String = config.gateway1
    var gateway2:String = config.gateway2
    var connection:NetConnection = new NetConnection ;
    connection.addEventListener(IOErrorEvent.IO_ERROR,onFailure);
    try{
        connection.connect(gateway1);
        trace("It went in to the try of the connection.connect")
        //trace(connection);
        }
    catch(error:IOError){

        trace("It didn't work",error);
    }

var responder:Responder = new Responder(onResult,onFault);//onResult and onFault can be any name
var array:Array = new Array(kioskNum,questionNum);
try 
    {connection.call("dataconnect.retrieveInfo",responder,array);
    trace("It went in to the try of the connection.call");}
catch(error:IOError){
    trace("It didn't work",error);}
//trace(gateway1);
4

2 回答 2

4

可以使用 FaultEvent.FAULT 捕获加载 WSDL 时的错误

...
webService.addEventListener(FaultEvent.FAULT, onWsdlLoadError);
webService.loadWsdl(<wsdl>);
...
protected function onWsdlLoadError(event:FaultEvent):void {
    trace("wsdl load error: " + event.fault);
}

希望这可以帮助。

于 2012-11-28T09:27:09.137 回答
3

您需要为NetStatusEvent.NET_STATUS添加事件侦听器并检查信息

    connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

    function netStatusHandler(event:NetStatusEvent):void {
        switch (event.info.code) {
            case "NetConnection.Connect.Failed":
                //Do something on Failed
                break;
            case "NetConnection.Connect.Closed":
                //Do something on Closed
                break;
            case "NetConnection.Call.Failed":
                //Do something on Call.Failed
                break;
        }
    }
于 2012-04-05T20:44:26.713 回答