17 Replies Latest reply on Feb 19, 2013 7:28 AM by Trevorׅ

    eventName for checkboxControls EventListener [UI]

    Trevorׅ Adobe Community Professional

      Does any one know how to add an eventListener to a checkboxControl (not a checkbox)? I can't get a recognised event name.

       

      Thanks

       

      Trevor

        • 1. Re: eventName for checkboxControls EventListener [UI]
          Jump_Over Level 5

          Hi,

           

          Wouldn't it be

           

          checkbox.onClick = function ()

          {...}

           

          hope...

          • 2. Re: eventName for checkboxControls EventListener [UI]
            Trevorׅ Adobe Community Professional

            No.

             

            That's one of the reasons I wrote "checkboxControl (not a checkbox)"

            I should be able to use checkboxControl.addEventListener (eventType: string, handler: varies[, captures: bool=false])

            But I can't get any event type to work.

            • 3. Re: eventName for checkboxControls EventListener [UI]
              TᴀW Adobe Community Professional & MVP

              what is a checkbox control?

              • 4. Re: eventName for checkboxControls EventListener [UI]
                Trevorׅ Adobe Community Professional

                Hi Ariel

                 

                It's a widget.

                 

                http://jongware.mit.edu/idcs5js/pc_CheckboxControl.html

                I think it's a legacy item that used to be from before Checkboxes came about.

                They look the same as check boxes but are coded differently, using

                 

                linkScales = checkboxControls.add ();

                 

                instead of

                 

                linkScales = myPanel.add("checkBox")

                 

                So if your in an inquisitive frame of mind your probably wondering why on earth is he using the method that doesn't work? Right?

                 

                The answer is that I am adapting an existing script written by some sadist in which the UI is set up in a way that you can use checkboxControls but not use checkboxes.

                 

                Even regular checkboxes have there hicups, see http://forums.adobe.com/message/3568344#3568344

                But compared to checkboxControls their a piece of cake.

                 

                Regards

                 

                Trevor

                • 5. Re: eventName for checkboxControls EventListener [UI]
                  TᴀW Adobe Community Professional & MVP

                  Ah, I think I understand.

                   

                  The InDesign scripting DOM provides an easy way of making simple UI, and

                  uses checkboxControls. ScriptUI uses checkboxes.

                   

                  Well, I haven't tried this, and you haven't posted any code to show what

                  you have tried, but the documentation says:

                   

                  myCheckbox.addEventListener(eventType:string, eventHandler);

                   

                  ... so I guess something like that should work?

                   

                  Not sure what strings are allowed, is "onClick" not one of them? You'd

                  probably be able to find that info in the InDesign scripting Guide.

                   

                  Ariel

                  • 6. Re: eventName for checkboxControls EventListener [UI]
                    Trevorׅ Adobe Community Professional

                    NO!

                    "onClick" is not one of them.

                    That is my problem.

                    Hit the nail on the head,

                    Spot on.

                    Bullseye.

                    Etc.

                     

                    I want to know what eventType strings are allowed.

                    Iv'e look in the guides.

                    • 8. Re: eventName for checkboxControls EventListener [UI]
                      Vamitul Level 4

                      i think is 'onChange'.. i think..

                      edit:

                      i don't think you can use event listeners for simple ui's like that, since they are not dinamic. i'we just been looking into the samples that came with indesign, and i haven't seen any example of that.

                      • 9. Re: eventName for checkboxControls EventListener [UI]
                        Trevorׅ Adobe Community Professional

                        I suspect that you are correct but the reference says you can.

                        http://jongware.mit.edu/idcs5js/pc_CheckboxControl.html

                        This could well be a mistake.

                         

                        Anyway here's some (ugly) code to experiment with and Ariel can see a real live checkboxControl

                         

                        myDialog = app.dialogs.add()
                        with (myDialog)
                            {
                                with (dialogColumns.add())
                                    {
                                        mycheckboxControl = checkboxControls.add ({staticLabel:"\u00A0 This is a checkboxControls", checkedState: true});
                                    }
                                }
                        /*********************************************************************************************************************
                            now for the tricky bit ...................................
                        **********************************************************************************************************************/
                        // myEventListener = mycheckboxControl.addEventListener("onChange", doSomething) // onChange doesn't work this line will cause an error
                        myDialog.show()
                        function doSomething() {alert ("Bingo")}
                        
                        • 10. Re: eventName for checkboxControls EventListener [UI]
                          TᴀW Adobe Community Professional & MVP

                          I've always had it at the back of my mind that regular InDesign dialogs

                          can't have event listeners attached to them. They're very basic. That's

                          one of the advantages of ScriptUI. Documentation notwithstanding....

                           

                          (If you can get it to work, let us know!)

                          1 person found this helpful
                          • 11. Re: eventName for checkboxControls EventListener [UI]
                            Vamitul Level 4

                            here's my trick:

                            myDialog = app.dialogs.add()
                            with (myDialog)
                                {
                                    with (dialogColumns.add())
                                        {
                                            mycheckboxControl = checkboxControls.add ({staticLabel:"\u00A0 This is a checkboxControls", checkedState: true});
                                        }
                                    }
                            /*********************************************************************************************************************
                                now for the trick bit ...................................
                            **********************************************************************************************************************/
                            
                            
                            for (prop in mycheckboxControl.events) {alert(prop+':'+mycheckboxControl.events[prop])};
                            //myEventListener = mycheckboxControl.addEventListener("onChange", doSomething) // onChange doesn't work this line will cause an error
                            myDialog.show()
                            function doSomething() {alert ("Bingo")}
                            

                            so.. id does have a "events" property, and a "eventListeners"

                            but where to go from here i got no idea.

                            1 person found this helpful
                            • 12. Re: eventName for checkboxControls EventListener [UI]
                              Trevorׅ Adobe Community Professional

                              Yep,

                               

                              You have a good point

                               

                               

                              Changing your loop to

                              for (prop in mycheckboxControl) {alert(prop)};

                              makes it a bit more visual.

                              _2013-02-19_16-16-26.png_2013-02-19_16-17-09.png

                              But as you put it "where to go from here i got no idea"

                               

                              I think we need one of the big 4 to help

                              • 13. Re: eventName for checkboxControls EventListener [UI]
                                [Jongware] Most Valuable Participant

                                Trevor,

                                 

                                There seem to be *no* supported events for CheckBoxControls. Compare, for example, Document -- the list of supported events (AFTER_ACTIVATE, AFTER_EXPORT, etc.) is listed right below the 'usual' properties of the Document class. I'd have to check what the original XML file says what type this list is; I think it was something like 'class-specific properties'.

                                 

                                Anyway, it may be all scriptable InDesign objects have the properties 'events' and 'eventListeners' and the methods 'addEventListener' and 'removeEventlistener', because they are all based on one common 'Generic_InDesign_Object'. The functions and properties are there, but ... of course every type of object should have its own list of events it can handle. After all, your checkbox would not profit from having a "BEFORE_SAVE_AS" event.

                                 

                                So, one may deduce events were added on a per-object type basis; and apparently Adobe did not think it was useful to add events to your checkbox control. And this may be because the "old style" dialogs are being phased out and replaced by the much more powerful ScriptUI.

                                • 14. Re: eventName for checkboxControls EventListener [UI]
                                  Vamitul Level 4

                                  two questions:

                                  1) isn't easier to just rewrite the whole damn thing using scriptUI?

                                  2) what windows skin are you using?

                                  • 15. Re: eventName for checkboxControls EventListener [UI]
                                    Trevorׅ Adobe Community Professional

                                    Hi Jongware,

                                     

                                    Finally one of the big 4

                                    I think that explains it very well.

                                     

                                    Thanks

                                     

                                     

                                     

                                    @ Vamitul

                                     

                                    1) No, I just made do without the eventListner

                                    2) Windows 7 (the screenshot came a bit mess up - my fault)

                                    here's a better one

                                    _2013-02-19_16-38-50.png

                                    • 16. Re: eventName for checkboxControls EventListener [UI]
                                      TᴀW Adobe Community Professional & MVP

                                      Hi Trevor,

                                       

                                      A little insulting there for the rest of us trying to help you.

                                      Especially when I answered your question in my previous post -- there is

                                      no way of doing this with the InDesign DOM dialog object.

                                       

                                      ...

                                      • 17. Re: eventName for checkboxControls EventListener [UI]
                                        Trevorׅ Adobe Community Professional

                                        Sorry Ariel and the rest.

                                         

                                        I didn't mean any insult to anyone and really appreciate the help.

                                         

                                        I did find Jongwares explanation very convincing.

                                         

                                        Anyway, it may be all scriptable InDesign objects have the properties 'events' and 'eventListeners' and the methods 'addEventListener' and 'removeEventlistener', because they are all based on one common 'Generic_InDesign_Object'. The functions and properties are there, but ... of course every type of object should have its own list of events it can handle. After all, your checkbox would not profit from having a "BEFORE_SAVE_AS" event.

                                         

                                        I'm pretty convinced the above statement would be true with the word "it may be" erased and that your answer is also correct

                                         

                                        With thanks and apologies,

                                         

                                        Trevor