11 Replies Latest reply on Nov 21, 2010 11:15 PM by Anil Yadav

    [CS4]: ScriptUI

    Anil Yadav Level 1

      Hi,

      I have created a window with script UI having two panels ‘ListBox’ and ‘ScriptUI.newImage’. The first panel contains the Figure List and the second panel contains the corresponding Graphic. I have written a small list.onChange function which change Graphic on selection but before loading the requested graphic it doesn’t wipe-out the previous one and appear clubed. Could you please suggest how to deal with it?

       

      Screen shot of default image (Scree1.bmp). This is appearing perfectly OK.

      Screen1.jpg

      Screen shot of selected first graphic (Scree2.bmp). Figure 1 is behind the default image. Marked with red.

      Screen2.jpg

       

      Here is the code I’m using:

       

      
      var dlg = new Window('dialog', 'Sample', undefined);
      dlg.btnPnl2 = 
      dlg.add('panel', undefined, 'My Sample List');
        dlg.btnPnl2.orientation = 
      "row"; 
         var list = dlg.btnPnl2.add ('ListBox', [0, 0, 150, 75], 
      undefined);
         list.alignment="top";
         list.minimumSize=[100, 250];
         
      var item1 = list.add ('item', 'Figure 1');
         var item2 = list.add ('item', 
      'Figure 2');
         dlg.btnPnl2a = dlg.btnPnl2.add('panel');
         var i = ScriptUI.newImage( 
      new File('/c/t.png'));
         dlg.ImgTemplate = dlg.btnPnl2a.add ('image' , 
      undefined,  i);
         dlg.ImgTemplate.bounds=[0, 0, 300, 250]; 
         
      list.onChange = function ()
         {
          myTmpltName=list.selection;
          if 
      (myTmpltName.text=="Figure 1")
          {
           var i = ScriptUI.newImage( new 
      File('/c/Fig1.jpg'));
           dlg.ImgTemplate = dlg.btnPnl2a.add ('image' , 
      undefined,  i);
           dlg.ImgTemplate.bounds=[0, 0, 300, 250]; 
          
      }
          if (myTmpltName.text=="Figure 2")
          {
           var i = 
      ScriptUI.newImage( new File('/c/Fig2.jpg'));
           dlg.ImgTemplate = 
      dlg.btnPnl2a.add ('image' , undefined,  i);
           dlg.ImgTemplate.bounds=[0, 
      0, 300, 250]; 
          }
         }
      dlg.show();
      
      

       

       

       

      Thanks,

      Anil Yadav

        • 1. Re: [CS4]: ScriptUI
          Marijan Tompa [tomaxxi] Level 4

          Hey!

           

          Only problem is that you are creating new picture container.

          You just have to relink original container to new image like this:

           

          Delete this line:

          dlg.ImgTemplate = dlg.btnPnl2a.add ('image' , undefined,  i);
          

           

          and put this instead:

           

          dlg.ImgTemplate.image = i;
          

           

          In both onChange events.

           

          Hope that helps.

           

          --

          tomaxxi

          http://indisnip.wordpress.com/

          • 2. Re: [CS4]: ScriptUI
            Peter Kahrel Adobe Community Professional & MVP

            Adding to what Marijan mentioned, there's no need to list all figures in your onCange function. Here's how you could do your script:

             

             

             

            var figures = ['/c/Fig2.jpg', '/c/Fig2.jpg'];
            
            var dlg = new Window('dialog', 'Sample');
                dlg.btnPnl2 = dlg.add('panel', undefined, 'My Sample List');
                dlg.btnPnl2.orientation = "row";
                    var list = dlg.btnPnl2.add ('ListBox');
                    list.alignment="fill";
                    list.minimumSize.width = 150;
                    var item1 = list.add ('item', 'Figure 1');
                    var item2 = list.add ('item', 'Figure 2');
                dlg.btnPnl2a = dlg.btnPnl2.add('panel');
                    dlg.ImgTemplate = dlg.btnPnl2a.add ('image');
                    dlg.ImgTemplate.preferredSize = [300, 250]; 
                    
                list.selection = 0;
                dlg.ImgTemplate.image = figures[0];
                
                list.onChange = function ()
                    {
                    dlg.ImgTemplate.image = File (figures[list.selection.index])
                    }
            dlg.show(); 

             

             

            Peter

            1 person found this helpful
            • 3. Re: [CS4]: ScriptUI
              Anil Yadav Level 1

              Hi Tomaxi

               

              Thanks a lot its working great with graphics!

               

              I tried the same with flash swf file and again I got the same problem

              I'm using the following code instead of image

               

              This is default swf file which is working fine.

                 var flashPlayer = dlg.btnPnl2.add ("flashplayer", undefined);
                 flashPlayer.loadMovie(File("~/Desktop/Process.swf"));
                 flashPlayer.preferredSize = [270, 250];
              
              

               

              And using the below code on selection

              flashPlayer.loadMovie(File("~/Desktop/Process1.swf"));
              


              Could you please suggest on this.

               

              Many thanks,

              Anil Yadav

              • 4. Re: [CS4]: ScriptUI
                Anil Yadav Level 1

                Hi Peter,

                 

                I tried your script but when I select the figure 1 after selecting the Figure 2. It doesn't show the Figure 1's graphic.

                 

                Please check and suggest.

                 

                Thanks,

                Anil Yadav

                • 5. Re: [CS4]: ScriptUI
                  Peter Kahrel Adobe Community Professional & MVP

                  Change this line:

                   

                  dlg.ImgTemplate.image = figures[0];

                   

                  to this


                  dlg.ImgTemplate.image = File (figures[0]);

                   

                  Works fine for me.

                   

                  Peter

                  • 6. Re: [CS4]: ScriptUI
                    Anil Yadav Level 1

                    Appearing the same problem!

                     

                    Anyway thanks for your support and help!

                    • 7. Re: [CS4]: ScriptUI
                      Marc Autret Level 4

                      You probably need to call the layout.layout() method to update the panel.

                       

                      Also, if you need to display both images and swf from your listbox launcher, I suggest you create your own 'player', as illustrated below:

                       

                      // Medias declaration
                      //--------------------------------------
                      var medias = [
                           {name:"[Default]", type: 'image', path: "/c/t.png"},
                           {name:"Figure 1", type: 'image', path: "/c/Fig1.jpg"},
                           {name:"Figure 2", type: 'image', path:"/c/Fig2.jpg"},
                           {name:"Animation 1", type: 'flash', path:"~/Desktop/Process.swf"},
                           ];
                      
                      // Creates the dialog components
                      //--------------------------------------
                      var dlg = new Window('dialog', 'Sample', undefined),
                           pMain = dlg.add('panel', undefined, 'My Sample List'),
                           lMedias = pMain.add ('listbox'),
                           pView = pMain.add('panel');
                      
                      // Styling stuff
                      //--------------------------------------
                      pMain.orientation = 'row';
                      lMedias.alignment = 'fill';
                      pView.size = [300, 250];
                      // etc.
                      
                      // Feed the list -- excluding [Default]
                      //--------------------------------------
                      var i, n=medias.length;
                      for( i=1 ; i<n ; ++i )
                           lMedias.add('item', medias[i].name);
                      
                      // Player
                      //--------------------------------------
                      var showMedia = function(idx)
                           {
                           var md = medias[idx];
                      
                           if( pView.children.length ) pView.remove(0);
                                
                           switch( md.type )
                                {
                                case 'image' :
                                     pView.add('image', undefined,ScriptUI.newImage(File(md.path)));
                                     break;
                      
                                case 'flash' :
                                     pView.add('flashplayer', undefined, md.path);
                                     break;
                      
                                default:
                                     showMedia(0);
                                }
                           pView.layout.layout(true);
                           };
                      
                      
                      // Events
                      //--------------------------------------
                      lMedias.onChange = function()
                           {
                           showMedia(1 + this.selection.index);
                           };
                      
                      // Initialisation
                      //--------------------------------------
                      showMedia(0);
                      dlg.show();
                      

                       

                       

                      @+

                      Marc

                      1 person found this helpful
                      • 8. Re: [CS4]: ScriptUI
                        Peter Kahrel Adobe Community Professional & MVP

                        > You probably need to call the layout.layout() method to update the panel.

                         

                        There shouldn't be. The script works fine as I quoted it. After all, when the list changes (by selecting an item), the callback simply replaces one image with another and you don't need layout() to show the result.

                         

                        Peter

                        • 9. Re: [CS4]: ScriptUI
                          Marc Autret Level 4

                          Thanks, Peter, I was on the wrong track. Using layout.layout() only allows to rebuild a container, e.g. when children dimensions change. Right?

                           

                          Note. - At the first line of the script you posted:

                           

                           var figures = ['/c/Fig2.jpg', '/c/Fig2.jpg'];

                           

                          the same Fig2 path is repeated. This could explain why figures can't update if Anil tested your script from a copy-paste!

                           

                          @+

                          Marc

                          • 10. Re: [CS4]: ScriptUI
                            Peter Kahrel Adobe Community Professional & MVP

                            > the same Fig2 path is repeated.

                             

                            Ah - thanks, that must indeed be it. I used different file names and reverted to Anil's names for the post, but forgot to change a 2 into 1. Problem solved!

                             

                            Peter

                            • 11. Re: [CS4]: ScriptUI
                              Anil Yadav Level 1

                              Hi Peter and Marc,

                               

                              Thanks a lot for your suggestions. This is a great help for me and I really appreciate that.

                               

                              Regards,

                              Anil Yadav