1

I am trying to close() localconnection when connect() fails. But while closing connection it giving me '#2083 close failed because object is not connected'.

Thanks in advance.

try{
    connServer2Client.connect("_" + clientConnectionName);
}catch (error:ArgumentError) {
     trace("in catch connection established");
    connServer2Client.close();
    connServer2Client.connect("_" + clientConnectionName);
}

1 Answers1

0

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.

earlonrails
  • 4,966
  • 3
  • 32
  • 47