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

Communicate between JSX and JS

Participant ,
Nov 05, 2017 Nov 05, 2017

Copy link to clipboard

Copied

Hello

I am trying to send some kind of event from my Photoshop JSX to JS.

Documentation is pretty vague on the matter

CEP-Resources/CEP 8.0 HTML Extension Cookbook.md at master · Adobe-CEP/CEP-Resources · GitHub

It says basically that you need to do the following:

```

function sendEvent(event) {

    var externalObjectName = "PlugPlugExternalObject";

    var myLib = new ExternalObject("lib:" + externalObjectName);

    var event = new CSXSEvent();

    event.type = event;

    event.dispatch();

}

```

1. create ExternalObject – why is this needed? this object is not used afterwards? What is the `externalObjectName`, does it has to match my extension somehow, or it's a constant?

2. Create CSXSEvent, set type and dispatch it. This actually makes sense

The only problem I have so far is that my event isn't called back in my JS.

```

in JS:

csInterface.addEventListener("myClearEvent", clearCallback);

function clearCallback() {

     alert('clearCallback()');

}

in JSX:

function sendEvent(event) {

    var externalObjectName = "PlugPlugExternalObject";

    var myLib = new ExternalObject("lib:" + externalObjectName);

    var event = new CSXSEvent();

    event.type = event;

    event.dispatch();

}

...

sendEvent("myClearEvent");

```

Nothing happens, I get no alert showing up

Views

1.9K

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

Engaged , Nov 06, 2017 Nov 06, 2017

Hi,

you can try this:

// In the JS

csInterface.addEventListener("com.davide.customEvent", function(evt) {

  console.log('Data from the JSX payload: ' + evt.data);

});

// In the JSX

try {

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

} catch (e) { alert(e) }

if (xLib) {

  var eventObj = new CSXSEvent();

  eventObj.type = "com.davide.customEvent";

  eventObj.data = "some payload data...";

  eventObj.dispatch();

}

It works even if you run the JSX part from ESTK.

Personal plug: this snip comes f

...

Votes

Translate

Translate
Engaged ,
Nov 06, 2017 Nov 06, 2017

Copy link to clipboard

Copied

Hi,

you can try this:

// In the JS

csInterface.addEventListener("com.davide.customEvent", function(evt) {

  console.log('Data from the JSX payload: ' + evt.data);

});

// In the JSX

try {

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

} catch (e) { alert(e) }

if (xLib) {

  var eventObj = new CSXSEvent();

  eventObj.type = "com.davide.customEvent";

  eventObj.data = "some payload data...";

  eventObj.dispatch();

}

It works even if you run the JSX part from ESTK.

Personal plug: this snip comes from my Adobe Photoshop HTML Panels Development course (paid) that you can find here http://htmlpanelsbook.com/

I've also a (free) ongoing series of blogposts about PS Panels here: HTML Panels | Photoshop, etc.

Cheers,

Davide

Davide Barranca - PS developer and author
www.ps-scripting.com

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 ,
Nov 06, 2017 Nov 06, 2017

Copy link to clipboard

Copied

Thanks.

Guess it was some kind of internet fluke – I already resolved this issue and posted the solution, linking to your article.

Anyways, it works with this `if xLib` for some reason

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
Engaged ,
Nov 06, 2017 Nov 06, 2017

Copy link to clipboard

Copied

LATEST

I think the problem was that your initial code didn't provide any event.data, and the event.type wasn't correct.

Think about the PlugPlugExternalObject as a way to load the needed lib – if everything's ok, i.e. xLib != undefined, then you can send the event.

Davide Barranca - PS developer and author
www.ps-scripting.com

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