Copy link to clipboard
Copied
Hi
​I have a basic problem with dropdown list.
my variable alignTxt doesn't work outside function.
​var alignmentBox = alignmentBoxGroup.add("dropdownlist", undefined, ["Left","Center", "Right"]);
​
​ alignmentBox.onChange = function (){
if(this.selection.index==0){
var alignTxt = "ParagraphJustification.LEFT_JUSTIFY";
};
if(this.selection.index==1){
var alignTxt = "ParagraphJustification.CENTER_JUSTIFY";
};
if(this.selection.index==2){
var alignTxt = "ParagraphJustification.RIGHT_JUSTIFY";
};
}
​
​myText.justification = alignTxt;
​
Thanks in advance!
Copy link to clipboard
Copied
The scope of a variable is limited to the function in which it is defined, so you just need to declare the variable outside the function:
var alignTxt;
Then not have the var where the variables are used inside the function.
Copy link to clipboard
Copied
Thank you for your fast response Paul.
I've tried it earlier but it doesn't work.
I'm getting undefined on alert(alignTxt);
Copy link to clipboard
Copied
Well you definitely have an issue with variable scope (limited to that onChange function) in the above example, and it would probably still return undefined until it had gone through your onChange function at least once, unless when you declare it initially you give it a default value.
Put in lots of $.writeln(alignTxt) type stuff throughout your code to keep track of things by checking the results in the ESTK javascript console (make sure you've enabled javascript debugger in the AE prefs).
If you still can't figure it out you'll probably have to post more code so we can see the whole thing in action.
Copy link to clipboard
Copied
Thank you for your time Paul.
I've solved it.
I should remove quotation marks from variables
and set var alignTxt = ParagraphJustification.LEFT_JUSTIFY; as default variable.