Dialog box - does not have a constructor

2019-09-13 15:23发布

问题:

I'm having intermittent success with trying to create a dialogue box. The code is valid.

try
{
    // Create an empty dialog window near the upper left of the screen
    var dlg = new Window("dialog", "Alert Box Builder");
    dlg.frameLocation = [100,100];
    dlg.show();
}
catch(e)
{
    alert(e);
}

Sometimes it works, sometimes I get the error:

Error 22:Window does not have a constructor

I have no idea why. Deleting Photoshop preferences and/or running as Administrator doesn't seem to work (running CC on Win7).

回答1:

I can offer no explanation to this, other than sometimes Photoshop corrupts the preferences file and this causes further problems in creating user interface elements. Certainly I've experienced this on Windows. The best thing to do is get rid of the preferences file. This is a big pain as it'll set Photoshop back to it's default setup. So, before deleting the preferences file, make snapshots of the preferences file and if you can save your workspace as something other than default mode.

The preferences file is found as Adobe Photoshop SCX Prefs.psp in the C:\YOURUSERNAME\AppData\Roaming\Adobe\Photoshop SCX

where CSX is the version number of Photoshop

  • Delete the preferences file.
  • Restart Photoshop (It'll create a new preferences file)
  • Close down Photoshop.
  • Copy a back up of your preferences over the newly created one.
  • Restart Photoshop.

The obvious thing to do would be to skip over the first stages and just copy over the preferences file with a back up. This doesn't force Photoshop to generate new preferences and the windows constructor error will persist.

Can I suggest you amend your code to something like

catch(e)
{
    //alert(e);
   alert("Photoshop was unable to create User Interface"); 
}

That way you'll know it's a window construction error and not just an error in your code. There's really no way round it, I'm afraid.