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

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

Contributor ,
Sep 20, 2016 Sep 20, 2016

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

try

lolk = 10;

and not

var lolk = 10;

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

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.

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

result[8] is the callback

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

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.

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