12 Replies Latest reply on Feb 26, 2013 3:04 AM by Trevorׅ

    Why do i lose my variables after exit of function? [CS6-js]

    Beliakov Level 1

      i try to read from my file (if it exists) string for getting  print style name. I did this in function.

      var mSty = ''; // initiated variable

      var mIs; // var for exist-yes/no-indicator

       

      function findFile(mIs, mSty) {

      fname = app.activeDocument.filePath + '/' + 'prn_style.txt';

          if(!File(fname).exists) {

              mIs = false

              }

          else     

              {

                  mIs = true

                  var f = File(fname); ////////////////////////

                  f.open("r");

                      while(!f.eof) {

                      mSty = f.readln();   

                      }

          f.close();

          } // end if exists

      return mIs;

      return mSty; ///// here "mSty" stil DOES exist...

      }

      ///////and here "mSty" already DOESN't exit. Why?

      if (mSty == null) alert ('no file') else alert(mSty);

       

      So i can't get a string from file, cause variable dissapears.

      In breif: i need to get two variables from one function.