1

I am having a problem with correctly identifying when a connection was NOT made while trying to connect to an external file. It works fine if I have the localhost on (which is config.gateway1) but if I turn the server off I only get an error:

"Error opening URL 'http://localhost/amfphp/gateway.php'"

I've tried setting up try catches on both the connection and the call. I also set up an event listener which is supposed to call a function onFailure (which at this point just traces the fail). The error seems to occur when I make the call, and it doesn't work...but I can't seem to direct what happens when the error occurs.

    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);
Mike Wilding
  • 49
  • 1
  • 5

2 Answers2

4

Error while loading WSDL can be captured by using FaultEvent.FAULT

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

Hope this helps.

hhn
  • 41
  • 2
3

You need to add event listener for NetStatusEvent.NET_STATUS and check the info:

    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;
        }
    }
Engineer
  • 47,849
  • 12
  • 88
  • 91
  • When debugging, I also use a default case to trace out all the other net status event codes, this can be very enlightening at times `default: trace(event.info.code); break;` – Sunil D. Apr 05 '12 at 23:59
  • Thanks both so much. apparently the case I was looking for was "NetConnection.Call.Failed" for some reason. The trace of the code helped me figure that out...Thanks a million!!!! – Mike Wilding Apr 06 '12 at 19:23
  • @umamiMike I have updated my answer , so you probably can accept it. – Engineer Apr 07 '12 at 07:48