Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


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

Explorer ,
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

97

Likes

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

Adobe Community Professional , 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"); ...

Likes

Translate

Translate
Advocate ,
Oct 21, 2021 Oct 21, 2021

Copy link to clipboard

Copied

Likes

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
Explorer ,
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.

 

 

Likes

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
Adobe Community Professional ,
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

Likes

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
Explorer ,
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...

 

Likes

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