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
Participant
December 14, 2020

I want to receive data back from CSXSEvent in MacOS. Are you have solution?

Thank you!

Community Expert
December 14, 2020

Hi @AnonID,

Events are one-way means of communication. If you need to send data from jsx to js then you can use the code snippet I wrote above. If you need to send data from js to jsx then you can do that directly by calling a method. Can you specify what exactly you are trying to do?

-Manan

-Manan