2 Replies Latest reply on Mar 7, 2014 7:37 AM by NoPrevaricator

    InDesign CC Listbox.removeAll() problems

    NoPrevaricator Level 1

      aHello Forum:

       

      Using InDesign CC on a Mac 10.7.5 I am creating a UI that looks like this (I cut a lot out for brevity's sake):

       

      //  Declared as globals.

      var URLList   = new Array();

      var EMailList = new Array();

       

      var DoubleListWindow               = new Window("dialog", "List Inspection Dialog", [200,  200, 900, 1000]);

         

      DoubleListWindow.Button1  = DoubleListWindow.TopButtonPanel.add("button", [165, 10, 345, 30], "Expand List 1");

      DoubleListWindow.Button2  = DoubleListWindow.TopButtonPanel.add("button", [355, 10, 535, 30], "Expand List 2");

       

      //  The other button looks the same except it works with the other list.

      DoubleListWindow.Button2.onClick = function()

      {   

           ListToUse = List2;

           LoadList(List2, SingleListEWindow.AddressListBox);       

           SingleListEWindow.show();       

      }

       

       

      DoubleListWindow.Box1  = DoubleListWindow.ListBoxPanels.add(    "listbox", [  0,   5, 345, 760], {multiselect: false, items:   URLList});

      DoubleListWindow.Box2  = DoubleListWindow.ListBoxPanels.add(    "listbox", [355,   5, 700, 760], {multiselect: false, items: EMailList});

      LoadList(List1, DoubleListWindow.Box1);

      LoadList(List2, DoubleListWindow.Box2);

       

       

      And finally, LoadList looks like this:

       

      function LoadList(List, Box)

      {

         var TempList = new Array();

          

         // If I comment this out LoadList works just fine except that the entries in the listbox double. 

         Box.removeAll();

        

         // This was added to see if it would fix the problem.  It did not.

         // If I create a TempList and use it to fill the listbox, on the second call to LoadList

         // the two arrays are made invalid and the listbox does not fill

         for(var b = 0; b < List.length; b++)

             TempList[b] = List[b];

          

         var a = 0;

         while(a < TempList.length)

         {

            Box.add("item", TempList[a]);

            a++;

         }

      }   

       

      SingleLIstWindow looks like this (pared down for brevity):

       

      var SingleListEWindow             = new Window("dialog", "List2", [300,  300, 1000, 1100]);  

      SingleListEWindow.AddressListBox  = SingleListEWindow.MiddlePanel.add("listbox", [0,0,700,664], {multiselect: false});

       

      The problem is that LoadList works just fine on the first call to load the listbox, but if I dismiss listbox2, then recall it, the second call to LoadList tanks.

      The problem seems to be in the Box.removeAll() command.  Not only does it remove all line items from the box, but it causes List to become invalid.

      I have tried several permutations of this script to try to get this small section to work, but for some reason the removeAll command wants to remove more than just the line items in the list box.  It wants to remove everything in any array associated with the list box as well.

       

      I am going to try a few other ideas to see whether I can make this work.  Does anyone have any thoughts for what I am doing wrong?

       

      TIA

      John