15 Replies Latest reply on Mar 23, 2014 11:24 PM by Trevorׅ

    InDesign CC addEventListener not work

    XH.XH Level 1

      Don't work in InDesignCC addEventListener:

       

      var w =new Window ("dialog");

      var b = w.add ("listbox", undefined, "Qwerty");

      b.addEventListener("click", function (k){

          alert("detail: "+k.detail+'\r'+"X: "+ k.clientX+'\r'+"Y: "+ k.clientY);

      });

      w.show ();

       

       

      it's ok to work in ESTK and CS.

        • 1. Re: InDesign CC addEventListener not work
          Trevorׅ Adobe Community Professional

          Yes and no!

           

          But sadly more no than yes.

          If your right click on the listbox you will see the yes part if you left click on it the you see the no part.

           

          Of all the many SUI problems that came with CC I find this the most irritating

          I'm pretty sure the cause of it is the improved focus on the SUI object so I doubt the issue will be fixed within the next 10 to 20 years.

           

          Trevor

          • 2. Re: InDesign CC addEventListener not work
            XH.XH Level 1

            Thank you very much for Trevor.

             

             

            Yes, left click have no reaction, right click the is there will be a left click.

             

             

            They had run on CS script now have a problem, it seems only use onDoubleClick(), this will increase the user operation.

             

             

            Is there a better solution?

             

             

            Thank you again.

            • 3. Re: InDesign CC addEventListener not work
              Trevorׅ Adobe Community Professional

              XH.XH wrote:

               

                Yes, left click have no reaction, right click the is there will be a left click.

              Hi XH.XH

               

              It's not that the right click is "acting" as a left click rather all clicks (left, middle, right, or any other mouse button click if the mouse has them) are clicks, each button has a numeric value to it which can be retrieved on being clicked.

              The problem is cause by CC improved focus that's why it works on CS.

               

              For a solution you can fake most things, enjoy.

               

              // Fake List box  http://forums.adobe.com/message/5955686
              // by Trevor www.creative-scripts.com (coming soonish)
              // Note one has to pay attention to bubbling
              
              var w = new Window ('dialog', "Fake Item List Demo :-)"),
                    myAdd = w.add('statictext', undefined, "Fake itemList, Made by Trevor, available for custom scripts, www.creative-scripts.com (soonish)"),
                    clickMe =  w.add('statictext', undefined, "Click an Item"),
                    fakeListBox = w.add('panel'), // sometimes better to use group
                    p = w.add('panel'),
                    myListItemStrings = ["List Item 1", "List Item 2", "List Item 3", "List Item 4", "List Item 5", "List Item 6"],
                    myListItems = [],
                    l = myListItemStrings.length,
                    n, info1, info2, info3, infoBox,
                    green = w.graphics.newPen(w.graphics.PenType.SOLID_COLOR,[0,1,0], 1),
                    red = w.graphics.newPen(w.graphics.PenType.SOLID_COLOR,[1,0,0], 1);
              
              myAdd.graphics.foregroundColor = green;
              for (n = 0; n < l; n++)
                  {
                    myListItems[n] = fakeListBox.add('statictext', undefined, myListItemStrings[n]);
                    myListItems[n].preferredSize.height = 18;
                    myListItems[n].graphics.foregroundColor = red
                   };
              
              info1 = p.add('statictext');
              info2 = p.add('statictext');
              info3 = p.add('statictext');
              info4 = p.add('statictext');
              infoBox = p. add('edittext', undefined, undefined, {multiline: true});
              
              infoBox.preferredSize = [950, 200]
              info1.alignment = info2.alignment = info3.alignment = info4.alignment = 'fill';
              
              fakeListBox.orientation = 'column'; 
              fakeListBox.spacing = 0;
              fakeListBox.margins = [5,1,5,1];
              
              for (n = 0; n < l; n++)
                  {
                  myListItems[n].addEventListener ('click', function (k){
                  info1.text = (k.view.text + " was " + ((k.detail == 2) ? "double clicked " : "single clicked ") + " with mouse button: " + k.button);
                  info2.text = "Clicked X: "+ (k.clientX + k.view.location[0])
                                +  " Y: "+ (k.clientY + k.view.location[1])
                                + " possitons are in relation to the panel"; 
              
                  infoBox.text = "";
                  for (pr in k ) infoBox.text += (pr+ ": " + k[pr] + "\t" 
                                                  + ((Object(k[pr]).constructor.toString ().match (/Object/i)) ? Object(k[pr]).toSource().replace(/\,/g, ", ").replace(/:/g, ": ") : "")
                                                  + "\r");
                  colorListItem (k.view);
                  });
                   };
              
              fakeListBox.addEventListener ('mouseover', function (k){
                  info3.text = "Current pointer position: X: " + k.clientX + " Y: " + k.clientY + " Hey did you notice that the possitons are normaly in relation to the list item and not the panel! (Bubbling!) :-("
                  info4.text = "Current pointer position: X: " + (k.clientX + k.view.location[0]) + " Y: " + (k.clientY + k.view.location[1]) + " That's better :-)"
                  }
              );
              fakeListBox.addEventListener ('mouseout', function (k){
                  info3.text = info4.text = "";
                  });
              
              function colorListItem (item, items, group, x, l) {
                  group = item.parent;
                  items = group.children;
                  l = items.length;
                  while (l--) items[l].graphics.foregroundColor = (items[l] == item) ? green : red;
                  }
              
              w.show ();
              
              • 4. Re: InDesign CC addEventListener not work
                XH.XH Level 1

                Thank you very much for Trevor, give me a lot of inspiration.

                items is dynamic, and have a scroll bar, seems to have no better way

                • 5. Re: InDesign CC addEventListener not work
                  Marc Autret Level 4

                  Try to use 'mouseup' rather than 'click'.

                   

                  @+

                  Marc

                  • 6. Re: InDesign CC addEventListener not work
                    Trevorׅ Adobe Community Professional

                    I have been using mouseup quite a lot lately in place of click and my mind boggles how I missed that one.

                    • 7. Re: InDesign CC addEventListener not work
                      Marc Autret Level 4

                      Unfortunately the mouseup trick doesn't seem to work in CC 9.2 anymore

                       

                      It is becoming almost impossible to follow Adobe hazards in changing ScriptUI event rules…

                      • 8. Re: InDesign CC addEventListener not work
                        Trevorׅ Adobe Community Professional

                        Marc!

                         

                        You shouldn't have posted the mouseup tip.

                         

                        Somebody at Adobe must of spotted it and said "Right let's mess that one up for them!"

                         

                        Trevor

                         

                        P.s. Maybe it could be that it didn't work on CC 9 ME because I'm sure I must of tried it on that but it does work on CC9.1 ME.  Well it was good for the week that it worked.

                         

                         

                        P.p.s.

                        Worth sending a bug report? probably not.

                        • 9. Re: InDesign CC addEventListener not work
                          Trevorׅ Adobe Community Professional

                          Future of SUI scripting ?

                           

                          if (version <7) dothis();

                          else if (version <9) dothis2();

                          else if (version <9.1) dothis2();

                          else if (version <9.2) dothis3();

                          else if (version <9.21) dothis4();

                          else if (version <9.211) dothis5();

                          else if (version <9.212) dothis6();

                          ................

                          else if (version <10) dothis7862();

                          • 10. Re: InDesign CC addEventListener not work
                            Marc Autret Level 4

                            Yeah, CC is definitely a nightmare for developers

                             

                            On my side many users desperately demand—for months!!!—that I update my products and they do not understand how it can take so much time to get those scripts CC-compliant. But the fact is that we cannot even work around ScriptUI bugs in such an instable process. And all the time we spend in studying these crazy issues, it's less time to develop new tools. My job is to create programs, not to fix those from Adobe. They make us lose time and money in unprecedented scale. And they want us to promote the cloud and the whole shebang?

                             

                            @+

                            Marc

                            • 11. Re: InDesign CC addEventListener not work
                              Loic.Aigon Adobe Community Professional

                              Hi all,

                               

                              Funny enough I came back to SUI on CC yesterday after a few months out of it and my first reflex was to use addEventListener on a listbox control. As it didn't work I thought it was me a bit rusty. But I checked on CS6 and of course it worked. So I realized something was wrong with CC. And today I see this thread. I have always found ScriptUI more complicated than needed but it's true that if issues change from one version to another, it's not really encouraging to keep on using it.

                               

                              Good luck fellows,

                               

                              Loic

                              • 12. Re: InDesign CC addEventListener not work
                                Trevorׅ Adobe Community Professional

                                Ok this one sould hopefully work at least until they come out with CC9.2.1

                                Only works for edittexts and not listboxes, radiobuttons or checkboxes.

                                Radiobuttons and checkboxes can be dealt with by using images instead but the listboxes are more complicated.

                                 

                                 

                                var w =new Window ('dialog'),
                                      g =w.add('group'),
                                      e= g.add ('edittext', undefined, "Click me");
                                
                                ((+app.version[0] > 8) ? g : e).addEventListener('mouseup', details, false, false);
                                
                                function details (k){
                                if (k.eventPhase == 'target')
                                    {
                                        buttons = ["left", "middle", "right"]
                                        $.writeln (buttons[k.button] + " click");
                                    }
                                }
                                w.show ();
                                
                                • 13. Re: InDesign CC addEventListener not work
                                  Trevorׅ Adobe Community Professional

                                  Wow isn't SUI such fun

                                   

                                  Well what do you know, on the Mac  CC mouseup doesn't work too good but mousedown does (sort of) on windows it's the opposite.

                                   

                                  So we can do this.

                                   

                                  var w =new Window ('dialog'),
                                        g =w.add('group'),
                                        e= g.add ('edittext', undefined, "The quick brown fox");
                                  
                                  ((+app.version[0] > 8) ? g : e).addEventListener('mouse' + (/M/.test($.os[0]) ? 'down' : 'up') , details, false, false);
                                  
                                  function details (k){
                                  if (k.eventPhase == 'target')
                                      {
                                          buttons = ["left", "middle", "right"]
                                          $.writeln (buttons[k.button] + " click");
                                      }
                                  }
                                  w.show ();
                                  

                                   

                                  The result will be that on windows cs and cc and mac cs all clicks will be registered but on mac cc only click that are made on the edit box when it is not active will be registered.

                                   

                                  For me that's fine as that's the click that I want to look for when I have a radio button or checkbox that I want checked when their associated edit text has been click on.

                                  • 14. Re: InDesign CC addEventListener not work
                                    Marc Autret Level 4

                                    Hi Trevor,

                                     

                                    Additional observations on SUI event loop:

                                    http://indiscripts.com/blog/public/ScriptUIEvents.pdf

                                     

                                    (Not sure that can help you but who knows.)

                                     

                                    @+

                                    Marc

                                    • 15. Re: InDesign CC addEventListener not work
                                      Trevorׅ Adobe Community Professional

                                      Thanks Marc, that clears things up