3 Replies Latest reply on May 20, 2015 11:43 PM by John Smith Images

    addEventListener - change

    Chuck Uebele Adobe Community Professional & MVP

      I'm trying to learn how the event handlers work.  I set up a simple dialog to use MouseEvents.  I got the "click" event to work but when I try to set an event for "change" nothing happens.  Basiclly with the UI, if you change the selection in the dropdownlist, an alert should pop up sayiing "p2".  This was run on Photoshop CS5.  Is this a bug, or I'm I doing something wrong? Here's the code:


      var drop1 = ['one','two','three']

      var d

      createDlg ()

      function createDlg(){

            d = new Window('dialog','test')

                  d.p1 = d.add('panel',undefined,'panel 1')

                        d.p1.cbx1 = d.p1.add('checkbox',undefined,'checkbox 1');

                        d.p1.rb1 = d.p1.add('radiobutton',undefined,'radio button 1')

                        d.p1.rb2 = d.p1.add('radiobutton',undefined,'radio button 2')

                        d.p1.etx1 = d.p1.add('edittext',undefined,'edit text one')

                        d.p1.rb1.value = true


                  d.p2 = d.add('panel',undefined,'panel 2')

                        d.p2.cbx2 = d.p2.add('checkbox',undefined,'checkbox 2');

                        d.p2.dp1 = d.p2.add('dropdownlist',undefined,drop1);

                        d.p2.dp1.selection = 0


                  d.addBtn = d.add('button',undefined,'add')

                  d.removeBtn = d.add('button',undefined,'remove')

                  d.closeBtn = d.add('button',undefined,'close')


                  d.addBtn.onClick = function(){intD(d)}

                  d.removeBtn.onClick = function(){removeD(d)}

                  d.closeBtn.onClick = function(){d.close()}





      function intD(w){


            w.p1.addEventListener ('click', p1handler, false);

            w.p2.addEventListener ('click', p2handler, false);

            w.p2.dp1.addEventListener ('change', p2handler, true);




      function removeD(w){

            w.p1.removeEventListener ('click', p1handler, false);

            w.p2.removeEventListener ('click', p2handler, false);

            w.p2.dp1.removeEventListener ('change', p2handler, false);     




      function p1handler(){

            if(d.p1.rb1.value){d.p1.etx1.text = 'true'}

            else{d.p1.etx1.text = 'false'}



      function p2handler(){alert('p2')}