0 Replies Latest reply on May 4, 2010 5:06 PM by SOMEONEINTHEWORLD

    avoiding writing same function twice

    SOMEONEINTHEWORLD

      Hello,

       

      I want to avoid writing XMLSocket.prototype.onData = function(msg) twice.

       

      The msg static data are sent only at the first time.  It includes data for populating combo.  Depening on the combo selection, different set of data from msg are displayed.

       

      mySocket = new XMLSocket();
      mySocket.connect("127.0.0.1", 9999);
      System.security.loadPolicyFile("http://localhost/sockets/flash_policy.php");

       

      mySocket.onConnect = function(success) {
          if (success) {
              msgArea.htmlText += "<b>Server connection established!</b>";
              mySocket.send("connected"+"\n");
          } else {
              msgArea.htmlText += "<b>Not Connected</b>";
          }
      };
      mySocket.onClose = function() {
          msgArea.htmlText += "<b>Server connection lost</b>";
      };

       

      //for displaying static data
      XMLSocket.prototype.onData = function(msg) {
          //trace(msg);
          arr = msg.split("&");
          textHeadline.htmlText += arr[0];

       

              comboBox(arr);   
      };

       

      function displayData(combo_id)
      {
      XMLSocket.prototype.onData = function(msg) {
          arr = msg.split("&");
          textA.htmlText += arr[1];   
          textB.htmlText += arr[2];
      };

       

      }

       

      function comboBox(arr)
      {
        //combo code

        //selected combo id is sent to displayData

       

         displayData(combo_id);

      }

       

       

      Thanks