Skip to main content
Inspiring
March 10, 2009
Question

sharedobject.connect() fails .. AS3/Flex

  • March 10, 2009
  • 1 reply
  • 511 views
But about every 6th time the app starts, the sharedobject.connect(nc) fails to connect. I can see it fails because it does not sync, as well, it does not register on the server. If have a try, catch on the connect and it shows nothing. What should I be catching???


I'm setting it up like this: My question, what am I missing to catch an error when the SharedObject.connect() fails?
In AS2.0, the connect would return a true or false. In AS3, which I'm using, it returns null.



nc.addEventListener(NetStatusEvent.NET_STATUS, onStatus );
nc.connect(..... );

public function onStatus( event:NetStatusEvent ):void{
var info = event.info;
switch( event.info.code ) {
case "NetConnection.Connect.Success":
connectSO();
break;
....
}

public function connectSO() {
try {
this.so = SharedObject.getRemote( this.sopath + "xxx", this.nc.uri, true);


this.so.addEventListener(SyncEvent.SYNC, onSync);
this.so.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError );
this.so.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
this.so.connect( m_nc );
this.so.client = this;
} catch (err:Error)
{
.....
}

}

//put these for the client
public function asyncError( evt:Object) {

}


public function netStatus( evt:Object) {

}

public function sync( evt:Object) {

}
    This topic has been closed for replies.

    1 reply

    jonporAuthor
    Inspiring
    March 11, 2009
    Well I found an error in FMS where the client is trying to access the sharedobject before the client.readAccess and client.writeAccess is set serverside. This is raising a tiny error in FMS, and the SharedObject is silently not connecting client side.

    I am using components server side. When the client connects, and is authenticated and the client connection was accepted and then the client was added to all loaded components. The .addClient in the component is where the read/write access is granted to the client. But on the client side,it was trying to sync (i.e read) the sharedobject before the .addClient is called. It was a race condition.

    So I changed the order to authenticate, then add the client to the server-side components and then do the application.acceptConnection(client). Fortunately that didn't break anything and logically makes sense.

    But.. my question still stands.. how do I capture such an error client side? In general, it would sure be nice to know when a connection attempt fails or is rejected.