Skip to main content
Chuck Uebele
Community Expert
Community Expert
June 26, 2012
Question

addEventListener - change

  • June 26, 2012
  • 1 reply
  • 2179 views

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()}

      d.show()

      }

function intD(w){

      ScriptUI.events.createEvent('MouseEvent');

      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')}

This topic has been closed for replies.

1 reply

Inspiring
June 26, 2012

I have found that mouse events don't work correctly for me with Photoshop CS5. The same dialog that fails there works as expected in other Adobe apps that support ScriptUI.

Chuck Uebele
Community Expert
Community Expert
June 26, 2012

Thanks, Mike.  I'll have to try this on CS6 and see what happens, but we haven't upgraded at work yet to CS6, and I might need this backward compatable for a bit.

John Smith Images
Participant
May 21, 2015

And do Adobe have a fix for that???

I mean if the eventlisteners work on the controls why not lauch it from a dialog box at PS start? Is it possible?