Skip to main content
Inspiring
September 15, 2020
Answered

Dispatching an Event from index.jsx to the index.js

  • September 15, 2020
  • 1 reply
  • 770 views

I'm trying to build some kind of export tool in photoshop and i'm struggaling a bit. I'm trying to find the answer but i can't seem to find it. Is it possible to dispatch an event from the index.jsx(host) file and listen to it inside the index.js(client)?

I've found this but i need it the other way around.

 
Folder structure looks like this.




This topic has been closed for replies.
Correct answer Manan Joshi

You could raise a CSXS event for this on the jsx end and then add eventhandler for this on the js end. Something like the following

 

//on the jsx end
var xLib = new ExternalObject("lib:\PlugPlugExternalObject");
if (xLib)
{
  var eventObj = new CSXSEvent();
  eventObj.type = "com.custom.event";
  eventObj.data = "hello"
  eventObj.dispatch();
}
//On the js end
var csInterface = new CSInterface();
csInterface.addEventListener("com.custom.event", function(event)
{
  alert(event.data)
});

 

-Manan

1 reply

Manan JoshiCommunity ExpertCorrect answer
Community Expert
September 15, 2020

You could raise a CSXS event for this on the jsx end and then add eventhandler for this on the js end. Something like the following

 

//on the jsx end
var xLib = new ExternalObject("lib:\PlugPlugExternalObject");
if (xLib)
{
  var eventObj = new CSXSEvent();
  eventObj.type = "com.custom.event";
  eventObj.data = "hello"
  eventObj.dispatch();
}
//On the js end
var csInterface = new CSInterface();
csInterface.addEventListener("com.custom.event", function(event)
{
  alert(event.data)
});

 

-Manan

-Manan
NH5EABAuthor
Inspiring
September 15, 2020

Hi Manan,

Thanks! This is exactly what i need!!!!