View Full Version : trapping "Error opening URL"

03-22-2005, 08:10 PM
Is it possible to trap/catch this error so I can pop-up a dialog?

I do the following:
g_gatewayConnnection = NetServices.createGatewayConnection();
g_myService = g_gatewayConnnection.getService("myService");
trace("Connected:" + g_myService.serviceName);
and everything seems ok, but when the server is down and gateway.php is not accessible I eventually get a: "Error opening URL" error. I would like to recognize this and notify the user that the gateway service is unreachable.

NOTE: The error comes after my first attempt to use the service. For exampe:
g_myService.isValidUser(isValidUserReply, login, passwd);
I have defined both an onResult AND an onStatus method for isValidUserReply, but I don't seem to get an onStatus callback as I would expect...

03-22-2005, 09:25 PM

Wouldn't g_gatewayConnnection be set to null if the connection was unavailable? In which case you could just check for that?

Regards, snapple :)

03-23-2005, 11:45 PM
I tried that, but g_gatewayConnection always seems to be null?!?

I am using Flash MX and looking through the NetServices.as code, there doesn't seem to be a constructor for the NetServices class so I guess it returns <null>...

I've traced this as well and typeof(g_gatewayConnection) is <undefined> and it does seem to be <null> whether a connection is valid or not.

Here is my initialization code:
g_gatewayConnnection = NetServices.createGatewayConnection();
if (1) // g_gatewayConnection
g_myService = g_gatewayConnnection.getService("myService");
trace("Connected:" + g_myService.serviceName + " [" + g_gatewayConnection + "]");
g_isGatewayOpen = true;

03-24-2005, 07:58 AM
Why don't you try using instance of, instead of typeof(), which i think is only for built-in classes. If the variable g_gatewayConnnection, is only populated once an object is returned to it, then if instance of was false, the connection would have failed.

However, i don't think checking the g_gatewayConnnection would be the right place to check. This is only setting up a connection, not trying to establish a live connection to the server. You'll need to check where the getService() method is invoked.

Talking as an newbie with regards to remoting, please forgive me if you have already done this. But, why don't you check that the onResult() method of your class that you pass as a second parameter to the getService() method, if a connection is established, then the onResult() method (in your case function) will be envoked, if not, the onStatus() function will be invoked - just take appropriate action from there on.

Set up myResult as an instance of a class, with the methods i mentioned above.

myConnection.getService( myServicePath, myResult );

I don't know whether of not you have the book by Tom Muck - but he uses this technique in an early chapter.

Regards, snapple :)