Copy link to clipboard
Copied
Hello
I am trying to send some kind of event from my Photoshop JSX to JS.
Documentation is pretty vague on the matter
CEP-Resources/CEP 8.0 HTML Extension Cookbook.md at master · Adobe-CEP/CEP-Resources · GitHub
It says basically that you need to do the following:
```
function sendEvent(event) {
var externalObjectName = "PlugPlugExternalObject";
var myLib = new ExternalObject("lib:" + externalObjectName);
var event = new CSXSEvent();
event.type = event;
event.dispatch();
}
```
1. create ExternalObject – why is this needed? this object is not used afterwards? What is the `externalObjectName`, does it has to match my extension somehow, or it's a constant?
2. Create CSXSEvent, set type and dispatch it. This actually makes sense
The only problem I have so far is that my event isn't called back in my JS.
```
in JS:
csInterface.addEventListener("myClearEvent", clearCallback);
function clearCallback() {
alert('clearCallback()');
}
in JSX:
function sendEvent(event) {
var externalObjectName = "PlugPlugExternalObject";
var myLib = new ExternalObject("lib:" + externalObjectName);
var event = new CSXSEvent();
event.type = event;
event.dispatch();
}
...
sendEvent("myClearEvent");
```
Nothing happens, I get no alert showing up
Hi,
you can try this:
// In the JS
csInterface.addEventListener("com.davide.customEvent", function(evt) {
console.log('Data from the JSX payload: ' + evt.data);
});
// In the JSX
try {
var xLib = new ExternalObject("lib:\PlugPlugExternalObject");
} catch (e) { alert(e) }
if (xLib) {
var eventObj = new CSXSEvent();
eventObj.type = "com.davide.customEvent";
eventObj.data = "some payload data...";
eventObj.dispatch();
}
It works even if you run the JSX part from ESTK.
Personal plug: this snip comes f
...Copy link to clipboard
Copied
Hi,
you can try this:
// In the JS
csInterface.addEventListener("com.davide.customEvent", function(evt) {
console.log('Data from the JSX payload: ' + evt.data);
});
// In the JSX
try {
var xLib = new ExternalObject("lib:\PlugPlugExternalObject");
} catch (e) { alert(e) }
if (xLib) {
var eventObj = new CSXSEvent();
eventObj.type = "com.davide.customEvent";
eventObj.data = "some payload data...";
eventObj.dispatch();
}
It works even if you run the JSX part from ESTK.
Personal plug: this snip comes from my Adobe Photoshop HTML Panels Development course (paid) that you can find here http://htmlpanelsbook.com/
I've also a (free) ongoing series of blogposts about PS Panels here: HTML Panels | Photoshop, etc.
Cheers,
Davide
Copy link to clipboard
Copied
Thanks.
Guess it was some kind of internet fluke – I already resolved this issue and posted the solution, linking to your article.
Anyways, it works with this `if xLib` for some reason
Copy link to clipboard
Copied
I think the problem was that your initial code didn't provide any event.data, and the event.type wasn't correct.
Think about the PlugPlugExternalObject as a way to load the needed lib – if everything's ok, i.e. xLib != undefined, then you can send the event.