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

In extension, how to call function from JavaScript file (.js) inside ExtendScript file (.jsx)?

Participant ,
Oct 21, 2021 Oct 21, 2021

Copy link to clipboard

Copied

I have javascript file (.js) with some functions I would like to use that functions inside extendscript file(.jsx). Both javascript and extend script are part of extension.

 

I known for: 
var csInterface = new CSInterface();
csInterface.evalScript..

 

With this above I can use function from extedscript inside javascript but how I can do reverse process use functions from javascript inside extendscript?

TOPICS
Scripting , SDK

Views

998

Translate

Translate

Report

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 , Oct 22, 2021 Oct 22, 2021

What you can do is use CSXS events which are dispatched from the jsx when you need to call the js function. The js will already have a event handler registered for this event, inside this event handler you can call your js method and on completion of this method call you can call a jsx method using CSInterface to return back the retrurn data if any from jsx to js. To create a CSXS event you can use the following sample code

try {
   var xLib = new ExternalObject("lib:\PlugPlugExternalObject");
 
...

Votes

Translate

Translate
Adobe
Guide ,
Oct 21, 2021 Oct 21, 2021

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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
Participant ,
Oct 22, 2021 Oct 22, 2021

Copy link to clipboard

Copied

That code that is inside .js is not supported by .jsx (extendscript do not have all features of modern javascript) it will not run.

So it is not something that #include will solve.

It needs some workaround.

 

 

Votes

Translate

Translate

Report

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 ,
Oct 22, 2021 Oct 22, 2021

Copy link to clipboard

Copied

What you can do is use CSXS events which are dispatched from the jsx when you need to call the js function. The js will already have a event handler registered for this event, inside this event handler you can call your js method and on completion of this method call you can call a jsx method using CSInterface to return back the retrurn data if any from jsx to js. To create a CSXS event you can use the following sample code

try {
   var xLib = new ExternalObject("lib:\PlugPlugExternalObject");
   } catch (e) {
   }
   if (xLib) {
   var eventObj = new CSXSEvent();
   eventObj.type = "eventType";
   eventObj.data = "event data";
   eventObj.dispatch();
}

-Manan

Votes

Translate

Translate

Report

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
Participant ,
Oct 26, 2021 Oct 26, 2021

Copy link to clipboard

Copied

LATEST

Nice, thank you!

 

On this link there are some documentation about "Access HTML DOM from extend script":

https://github.com/Adobe-CEP/CEP-Resources/blob/master/CEP_11.x/Documentation/CEP%2011.1%20HTML%20Ex...

 

Votes

Translate

Translate

Report

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