3 Replies Latest reply on Jul 1, 2011 7:39 AM by Ned Murphy

    reading a file using AS2

    yatrikbuch

      Hello,

       

      I am calling one method at an interval of 3 sec.

      This method reads a file from server and then display its content.

      The file which is getting read is a log file which gets updated at regular interval.

      The issue is once some content read by AS then it is not getting updated that means after every execution of the function content of src variable below remains same even thou the source file is updated.

        • 1. Re: reading a file using AS2
          yatrikbuch Level 1

          The code is -

           

          function status(){
          trace("inside status function------");
          var my_data = new LoadVars();
          my_data.load("GraphTempLog/sample.log");
          //my_data.load("GraphTempLog/"+_level0.gc.getGraphName()+".log");
          };

          my_data.onData = function(src:String):Void {
          msgBoxComp.showAlert("","Counter "+num +src,"","","info",true);
          if (src != undefined) {
          myObj.output_txt.text = my_data.getBytesTotal()+ src;

          } else {
          myObj.output_txt.text = "No data generated "+num;
          }
          num++
          //src="";
          };

          • 2. Re: reading a file using AS2
            yatrikbuch Level 1

            Just to add - This works well when running from flash IDE but does not work when we are running it from web application.

            • 3. Re: reading a file using AS2
              Ned Murphy Adobe Community Professional & MVP

              If you are declaring that variable inside of that status function, it will not have scope outside of the function.  See if declaring it outside the function helps.

               

              var my_data;

               

              function status(){

                 my_data = new LoadVars();

               

                 my_data.onData = function(src:String):Void {
                     msgBoxComp.showAlert("","Counter "+num +src,"","","info",true);
                     if (src != undefined) {
                         myObj.output_txt.text = my_data.getBytesTotal()+ src;

                     } else {
                         myObj.output_txt.text = "No data generated "+num;
                     }
                     num++
                  };
                 my_data.load("GraphTempLog/sample.log");
              };

               

               

              Edit: Code changed above.  You might need to assign the onData within the function as well since when it executes it will not have anything define for it as is.