Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Explorer ,
Sep 15, 2020 Sep 15, 2020

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.

Schermafbeelding 2020-09-15 om 20.16.37.pngexpand image


TOPICS
Actions and scripting
657
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 15, 2020 Sep 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)
});

 

-Mana

...
Translate
Adobe
Community Expert ,
Sep 15, 2020 Sep 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 15, 2020 Sep 15, 2020

Hi Manan,

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 13, 2020 Dec 13, 2020

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

Thank you!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 14, 2020 Dec 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 14, 2020 Dec 14, 2020
LATEST

I want to send data from jsx to js, and return data back from js to jsx in this function. In Mac, code in jsx execute done before code in dispatch event execute. Are you have solution for that? Can you check inbox of me?

Thank you!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines