3 Replies Latest reply on Apr 17, 2010 10:48 PM by Harbs.

    [CS4 JS] Script UI refreshing statictext from function

    Skempy Level 1

      Hi,

       

      This script displays a simple floating palette with a Refresh button that when clicked should display a list of files in a particular folder. This list is retrieved using the getString([]) function which is commented out in the code below.

       

      For this example I have defined a myArray with values "one" and "two". I am OK with my function returning a valid array.

       

      The problem I am having is removing the list and replacing it everytime the Refresh button is clicked. The contents of the array are just added to the bottom of of the statictext.

       

      Any help would be appreciated.

       

       

       

      #targetengine "session"

       

      var w = new Window("palette","Open Neptune Jobs",undefined);
      w.addList = new Array();
      w.orientation = "column";
      w.Refresh = w.add("group",undefined);
      w.Refresh.Button3 = w.Refresh.add('button',undefined,"Refresh", {name:"refresh"});
      w.Refresh.Button3.onClick = function ()
              {
      myArray = ["one","two"]
      //myArray = getString ([]) // This is the function that gets my list of files
      w.myGroup = w.add( "group" );
      w.myGroup.orientation = "column";
       
         if ( this.window.addList.length > 0 ) {
                  this.window.myGroup.remove( this.window.addList.pop() );
                  this.window.layout.layout( true );
              }
                
      for( var i = 0; i < myArray.length; i++ )
        {
        myString = myArray[i]
        this.window.addList.push( w.myGroup.add( "statictext", undefined, myString ) );
        }    
        this.window.layout.layout( true );
              }

      w.frameLocation = [ 100, 100 ];
      w.show ();

       

       

      Thanks

       

      Simon.

        • 1. Re: [CS4 JS] Script UI refreshing statictext from function
          Bob Stucky Adobe Employee

          Skempy,

           

          I think this is what you want. Works in ESTK.

           

          Regards

           

          Bob

           

           

           

           

          // just to make it fun...
          makeArray = function() {
              var array = new Array();
              var a = parseInt( Math.random() * 20 ) + 1;
              for ( var i = 0; i < a; i++ ) {
                  array.push( parseInt( Math.random() * 100 ) );
              }
              return array;
          }

           

          var w = new Window("palette","Open Neptune Jobs",undefined);
          w.addList = new Array();
          w.orientation = "column";
          w.Refresh = w.add("group",undefined);
          w.Refresh.Button3 = w.Refresh.add('button',undefined,"Refresh", {name:"refresh"});
          w.Refresh.Button3.onClick = function () {
               var myArray = makeArray();
               if ( this.window.myGroup ) {
                   this.window.remove( this.window.myGroup );
              }
               w.myGroup = w.add( "group" );
               w.myGroup.orientation = "column";

              for( var i = 0; i < myArray.length; i++ ) {
                  w.myGroup.add( "statictext", undefined, myArray[ i ] );
              }
              this.window.layout.layout( true );

           

          }
          w.frameLocation = [ 100, 100 ];
          w.show ();

          • 2. Re: [CS4 JS] Script UI refreshing statictext from function
            Steven.. Level 3

            Bob (Adobe Engineer) wrote:

             

            // just to make it fun...

             

             

            Really nice !!

             

            Thanks

            • 3. Re: [CS4 JS] Script UI refreshing statictext from function
              Harbs. Level 6

              Steven.. wrote:

               

              Bob (Adobe Engineer) wrote:

               

              // just to make it fun...

               

               

              Really nice !!

               

              Thanks

              Yup!

               

              Wow this forum is really wild! <VBG>