1 Reply Latest reply on Mar 18, 2017 11:45 AM by Loic.Aigon

    Multi button click

    hamdifem Level 1

      Why does not alert when the button at the top is clicked

       

      win = new Window('dialog', 'Dialog Multi Button');  
      
      
      var grp2 = win.add('group');
      grp2.orientation = 'row';
      grp2.alignChildren = 'left';
      grp2.spacing = 0;
      
      
      var grp1 = win.add('group');
      grp1.orientation = 'row';
      grp1.alignChildren = 'left';
      grp1.spacing = 0;
      
      
      var myT = [];
      
      
      for(var i = 'A'.charCodeAt(0); i <= 'E'.charCodeAt(0);  ++i) {
       myT.push(String.fromCharCode(i));
       }
      
      
      
      
      var btns = []
      for (var i = 0; i < myT.length; i++){
      btns.push({c:grp1.add ("button", [0,0,150,50], myT[i])});
      btns[i].c.graphics.font = "Arial:30";
      
      
      }    
      var btns2 = []
      for (var i = 0; i < myT.length; i++){
      btns2.push({d:grp2.add ("button", [0,0,150,50], myT[i])});
      btns2[i].d.graphics.font = "Arial:15";
      btns2[i].d.onClick = function() {win.close(i)}  
      }         
      
      
      win.addEventListener ( 'keydown', onKeyPress );  
      win.center()  
      var myDlg = win.show()  
      function onKeyPress (evt) {  
       for (var i = 0; i < btns.length; i++){
        if (evt.keyName==btns[i].c.text) {  
        win.close(i)  
        };  
      } 
      }
      for (var i = 0; i < myT.length; i++){
      if(myDlg == i){  
      alert(myT[i]);
      }
      }
      
        • 1. Re: Multi button click
          Loic.Aigon Adobe Community Professional

          I don't have doc at hand but I think the return codes range isn't that extended.

          An alternative would be to "bind" a property to the window object itself.

           

          win.code = i;

          win.close(1);

           

          if ( win.show()==1 ) {

               alert( win.code);

          }

           

          FWIW

           

          Loic