1 Reply Latest reply on Aug 11, 2010 6:02 PM by Michael Thornburgh

    adobe startus text chat broken @ connection setup

    StepanskyR

      Posted my question here, I think I may get some better support here.

      http://stackoverflow.com/questions/3453969/adobe-startus-text-chat-broken-connection-setup

       

      ^ You can look there for better actionscript formatting. ^

       

       

      Called with jquery using

       

      $("#flashtxtchat").get(0).startTxtChat()

      pretty much a javascript call to startTxtChat() which causes the fail.

       

       

      • ArgumentError: Error #2126:
      • NetConnection object must be
      • connected. at
      • flash.net::NetConnection/get nearID()
      • at textchat/startChat() at
      • Function/http://adobe.com/AS3/2006/builtin::apply()
      • at
      • flash.external::ExternalInterface$/_callIn()
      • at ()

       

       

       

      <?xml version="1.0" encoding="UTF-8"?>

      <mx:Application height="1" width="1" verticalScrollPolicy="off" xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()" backgroundColor="#EEEEEE" verticalAlign="middle">

      <mx:Script>

      <![CDATA[

      import flash.events.*;

      import flash.external.*;

      import flash.net.*;

      import flash.system.*;

       

      import mx.containers.*;

      import mx.controls.*;

      import mx.core.*;

      import mx.events.*;

      import mx.styles.*;

      import mx.utils.*;

       

      private var netConnection:NetConnection;

      private var sendStream:NetStream;

      private var receiveStream:NetStream;

      private var strangerPeerID:String;

       

      public function init() : void

      {

      var url:* = FlexGlobals.topLevelApplication.url;

      var serverName:* = URLUtil.getServerName(url);

      if (!serverName.match(/(localhost|127.0.0.1)$/))

      {

      return;

      }

      ExternalInterface.addCallback("startTxtChat", this.startChat);

      ExternalInterface.addCallback("gotStrangerPeerID", this.gotStrangerPeerID);

      ExternalInterface.addCallback("sendMsg", this.sendMsg);

      ExternalInterface.addCallback("stopTxtChat", this.stopChat);

      ExternalInterface.call("flashtxtChat_init");

      return;

      }// end function

       

      public function startChat() : void

      {

      if (this.netConnection)

      {

      ExternalInterface.call("flashtxtChat_gotNearID", this.netConnection.nearID);

      }

      else

      {

      this.netConnection = new NetConnection();

      this.netConnection.addEventListener(NetStatusEvent.NET_STATUS, this.netConnectionHandler);

      this.netConnection.connect("rtmfp://stratus.rtmfp.net/key1-key2/");

      }

      return;

      }// end function

       

      public function gotStrangerPeerID(param1:String) : void

      {

      var _loc_3:NetStream = null;

      this.strangerPeerID = param1;

      var _loc_2:int = 0;

      while (_loc_2 < this.sendStream.peerStreams.length)

      {

       

      _loc_3 = this.sendStream.peerStreams[_loc_2];

      if (_loc_3.farID != this.strangerPeerID)

      {

      _loc_3.close();

      }

      _loc_2++;

      }

      this.receiveStream = new NetStream(this.netConnection, this.strangerPeerID);

      this.receiveStream.play("textchat");

      this.receiveStream.client = this;///temp added by me

      //this.strangerVideo.attachNetStream(this.receiveStream);

      return;

      }// end function

       

      public function sendMsg(msg: String) : void

      {

      sendStream.send("recvMsg", msg);

      }

       

      public function recvMsg(msg: String) : void

      {

      ExternalInterface.call("recvMsg", msg);

      }

       

      public function stopChat() : void

      {

      this.strangerPeerID = null;

      return;

      }// end function

       

      public function netConnectionHandler(event:NetStatusEvent) : void

      {

      var c:Object;

      var event:* = event;

      switch(event.info.code)

      {

      case "NetConnection.Connect.Success":

      {

      c = new Object();

      c.onPeerConnect = function (param1:NetStream) : Boolean

      {

      if (strangerPeerID == null)

      {

      return true;

      }

      return param1.farID == strangerPeerID;

      };// end function

      this.sendStream = new NetStream(this.netConnection, NetStream.DIRECT_CONNECTIONS);

      this.sendStream.client = c;

      this.sendStream.publish("textchat");

      ExternalInterface.call("flashtxtChat_gotNearID", this.netConnection.nearID);

      break;

      }

      case "NetConnection.Connect.Failed":

      {

      this.netConnection = null;

      ExternalInterface.call("flashCb_errorConnectingToStratus");

      break;

      }

      case "NetConnection.Connect.Closed":

      {

      this.netConnection = null;

      this.sendStream.close();

      this.sendStream = null;

      if (this.receiveStream)

      {

      this.receiveStream.close();

      this.receiveStream = null;

      }

      break;

      }

      default:

      {

      break;

      }

      }

      return;

      }// end function

      ]]>

      </mx:Script>

       

      </mx:Application>

        • 1. Re: adobe startus text chat broken @ connection setup
          Michael Thornburgh Adobe Employee

          in your function startChat(), you say

           

            if (this.netConnection)
                  {
                      ExternalInterface.call("flashtxtChat_gotNearID", this.netConnection.nearID);
                  }

           

          if the netConnection is in the process of connecting and startChat() gets called again, then the netConnection will not be null but will also not be connected.  you can only get the nearID if the netConnection is connected.