Quantcast
Channel: Adobe Community : Popular Discussions - Photoshop Scripting
Viewing all articles
Browse latest Browse all 12244

onClick event not working when trying to open an image in Photoshop CC2015 extension panel

$
0
0

Hi,

 

I'm currently writing an extension for CC2015 that opens a panel containing some tab layouts and some buttons.

I want the buttons to perform an onClick function that opens a PNG file in Photoshop but I cannot seem to get this to function to work as expected.

 

The main parts of my index.html for the extension that defines one of the buttons is:

 

<button class="BUTTON CLASS" id="BUTTON ID" role="BUTTON">BUTTON NAME</button>

 

I've then added an event listener function for the button (shown below) that works on finding the id name of the button:

 

<script type="text/javascript">

document.getElementById('BUTTON ID').addEventListener('click', onClickButton, false);

function onClickButton()

{

    var imageFile = new File("C:/FOLDER/FILENAME.png");

    docRef = app.open(imageFile);  

}

</script>

 

This piece of Javascript above falls over at this part here:

{

    var imageFile = new File("FILENAME.png");

    docRef = app.open(imageFile);  

}

 

For some reason the image will not open on button click with the above bit of script, however if I run this snippet in isolation by running the following in the ESTK the PNG file opens perfectly fine in Photoshop

     #target photoshop

    var imageFile = new File("FILENAME.png");

    docRef = app.open(imageFile);

 

 

I've tested the event listener and the onClick and everything appears to be fine here because if I replace the app.open portion of the script with a simple alert shown below the button returns a new window with the alert text present:

<script type="text/javascript">

document.getElementById('BUTTON ID').addEventListener('click', onClickButton, false);

function onClickButton()

{

     alert ("You Pressed Me");

}

</script>

 

If anyone has any pointers as to where I've gone wrong here that would be great as I can't see the wood for the trees right now.

 

Thanks.


Viewing all articles
Browse latest Browse all 12244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>