Adobe really screwed this one up IMO.
There should be a parameter to check or a function to call, which tells you the status. I.E.
connected = true or false
But there is not. So the best solution is multiple try catch functions which is terrible!
Here is the class I use. I use flex with html/javascript so this is in javascript but you can do something similar in as3.
function Connecter(){
this.LocalConnection = new LocalConnection();
this.LocalConnection.allowDomain("*");
this.connectionAttempts = 0;
this.localConnectionError = false;
this.connected = false;
}
Connecter.prototype.openConnection = function(channel){
try{
this.LocalConnection.connect(channel); //will throw error if connection is opened
} catch(e){
this.closeConnection();
this.LocalConnection.connect(channel); //try to reconnect again
}
this.connected = true;
};
Connecter.prototype.closeConnection = function(channel){
try{
this.LocalConnection.close(); //will throw error if connection is closed
} catch(e){ /* Already closed */ }
this.connected = false;
};
Connecter.prototype.connect = function(channel) {
var self = this;
while (self.connectionAttempts < 3 && !self.connected ) {
self.connectionAttempts += 1;
self.openConnection(channel);
}
};
So the connected will help tell you if you have a LocalConnection.