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

Getting data from JSX and store in the global JS scope?

Contributor ,
Sep 20, 2016 Sep 20, 2016

Copy link to clipboard

Copied

I'm developing a HTML5 panel for Photoshop and I have a problem.

I'm using CSInterface.evalScript() to call my JSX function - which returns a bunch of values.

The return is then handled by a function that resides as the second parameter to evalScript() - so far nothing strange (code example below).

var csInterface = new CSInterface();

var lolk = 10;

csInterface.evalScript("myJSX('param1')", function(result){

    lolk = result[8];

});

alert(lolk); // gives 10 - not the value returned from myJSX

The problem here is that I really, really need to be able to output things into the global scope in main.js. But with the above code you will not overwrite the global variable lolk. Instead the assignment is only within the scope of evalScript.

TOPICS
Actions and scripting

Views

886

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
Explorer ,
Oct 18, 2016 Oct 18, 2016

Copy link to clipboard

Copied

try

lolk = 10;

and not

var lolk = 10;

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
Explorer ,
Oct 18, 2016 Oct 18, 2016

Copy link to clipboard

Copied

The issue here is that evalScript is returning result[8] asyncronously. You need to put the alert inside the callback after you assign result[8] to lolk.

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
Advocate ,
Dec 09, 2024 Dec 09, 2024

Copy link to clipboard

Copied

LATEST

result[8] is the callback

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
Explorer ,
Jan 27, 2017 Jan 27, 2017

Copy link to clipboard

Copied

Hi Heimdaal,

Did you ever find a solution this problem? I'm running into the same issue where i cannot access the updated variable value outside the callback function.

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