#2083试图关闭localconnection

时间:2012-06-29 09:21:04

标签: actionscript-3 localconnection

我试图在connect()失败时关闭()localconnection。但是当关闭连接时,它会让我'#2083关闭失败,因为对象没有连接'。

提前致谢。

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

1 个答案:

答案 0 :(得分:0)

Adobe真的搞砸了这个IMO。

应该有一个要检查的参数或要调用的函数,它会告诉您状态。 I.E.

connected = true or false

但没有。所以最好的解决方案是多次尝试捕获功能,这很糟糕! 这是我使用的课程。我使用flex和html / javascript,所以这是在javascript中你可以在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);
  }
};

因此,如果您有LocalConnection,则连接将有助于告诉您。