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

Is there an alternate way to access a variable declared inside a function?

Explorer ,
Oct 01, 2008 Oct 01, 2008
The block of script below, I have a button that has an onClick function. When it is pressed, An Open dialog will open and when the use selects a file, the path of that file selected is returned in a text box. (Not included in the script) I have a few other values that need to be entered by the user before the script can continue. At the bottom of the dialog, I have an OK button. When the Ok button is pressed, I want the script to open the file at that particular time, not when it is selected from the open dialog. It works if I open the file after I browse for it with the open dialog, but to do it later in a different function is what I am having trouble with. I am new at Scripting for Adobe apps. Can someone help me out please? Thank you.

var stPath;

defineVars.STPnl.STBrowse.onClick = function browseST() {
var stbFile = File.openDialog("Select the Single Mugshot Key Template File", "PSD File:*.psd");

if (stbFile.fullName == null) {
//Take no action
}
else {
defineVars.STPnl.STPath.text = stbFile.fullName;
stPath = defineVars.STPnl.STPath.text;
//open(stbFile); (Doing it this way works, but I don't want it to execute in this sequence)
}
}
TOPICS
Actions and scripting
408
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
Community Expert ,
Oct 01, 2008 Oct 01, 2008
I'm not sure I understood you correctly, but it seems to me you need to define stbFile outside of the function as a global variable (like you did with stPath). That way it would maintain its value even when the function is finished and you could use it to open the file later on. Is this what you wanted to do?
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 01, 2008 Oct 01, 2008
Yes, correct. I attempted to try different variations of code, but it did not work either. Thanks.
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
Mentor ,
Oct 01, 2008 Oct 01, 2008
LATEST
Try having your function return stbFile
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